How to write assertions to read JSON nested objects using chai

25 Views Asked by At

I am trying to write some test cases using Insomnia and Chai where I am trying to read some JSON nested objects/values but struggling with syntax.

My JSON looks like below:

{
    "Response": {
        "requestId": "23232323",
        "tests": [
            {
                "test": {
                    "id": 1,
                    "ids": [
                        {
                            "code": 1,
                            "text": "yes"
                        },
                        {
                            "code": 2,
                            "text": "yes"
                        }
                    ]
                }
            }
        ]
    }
}

I am trying to write something like this but it obviously doesn't work because I can see it's not the correct syntax.

expect(body.Response.tests.test.ids.text).to.equal("yes");

Any guidance is appreciated.

0

There are 0 best solutions below