lundi 8 juin 2020

How to check the type of a nested property in mocha-chai?

Suppose the body of a response is something like that:

{
 "array": [
        {
            "porp1": {
                "subprop11": "a",
                "subprop12": [1,2]
            },
            "prop2": "c",
        },
        {
            "porp1": {
                "subprop11": "h",
                "subprop12": [3,2]
            },
            "prop2": "a",
        }
    ]
}

I know I can check that prop1.subprop11 exists for all elements of the array in this way:

res.body['array'].should.all.have.nested.property('prop1.subprop11');

and I know I can test a non-nested property type as:

res.body['array'].to.be.a('array');

however I cannot concatenate the check of nested properties, i.e. I cannot do something like:

res.body['array'].should.all.have.nested.property('prop1.subprop11').that.is.a("string");

or something similar.

How can I check it is a string?

Aucun commentaire:

Enregistrer un commentaire