TypeError: Cannot read property ‘content’ of undefined

Run the post request in postman
GET http://{{hostname}}:8086/cm/x/response?conversationId={{convoId}}

Click the send
The body return has the content array

[
   {
      "conversationId":"xxxxx",
      "event":"UI",
      "message":{
         "content":[
            {
               "command":"navigation",
               "namespace":"CT-InputTextField"
            },
            {
               "command":"resultSet",
               "data":{
                  "entity_type":"customer",
                  "hint":null,
                  "knowledge":[

                  ],
                  "title":"Please provide your customer name:"
               }
            }
         ]
      }
   }
]

In my test section, I do a test assertion in the field on the content array

let responseSchema = {
    "event": "UI",
    "message": {
        "content": [
            {
                "command": "navigation",
                "namespace": "ConversationTree-InputTextField"
            },
            {
                "command": "resultSet",
                "data": {
                            "entity_type": "customer",
                            "hint": null,
                            "knowledge": [],
                            "title": "Please provide your customer name:"
                }
            }
        ]
    },
    "target": "stella.lens"
}


pm.test('Check Customer Lookup InputTextField', () => {
    let jsonData = pm.response.json();
    pm.expect(jsonData.message.content[1].data.title).to.be.equal(responseSchema.message.content[1].data.title);
})

Expected behaviour
it should PASS

Screenshots
If applicable, add screenshots to help explain your problem.
but it gives an assertion Error
TypeError: Cannot read property ‘content’ of undefined

Hey @tohlaymui35,

From your example response body - it looks like it’s all in an array so changing your expect statement to jsonData[0].message.content[1].data.title would make the test pass.

thanks Danny, it fixed the issue
but I have another TypeError: Cannot read property ‘entity’ of undefined

my test section:

tests["Status code is 200"] = (responseCode.code === 200);

let responseSchema = {
    "event": "UI",
    "message": {
        "content": [
            {
                "command": "navigation",
                "namespace": "ConversationTree-Options"
            },
            {
                "command": "resultSet",
                "data": {
                    "knowledge": [
                        {
                            "entity": "quotable_object",
                            "value": "bucket"
                        },
                        {
                            "entity": "bucket_class",
                            "value": "Excavator Bucket"
                        },
                        {
                            "entity": "equipment_model",
                            "value": "320d l"
                        }
                    ],
                    "options": [
                        {
                            "onClick": "/inform{\"equipment_configuration\": \"reach\"}",
                            "text": "reach"
                        },
                        {
                            "onClick": "/inform{\"equipment_configuration\": \"mass ex\"}",
                            "text": "mass ex"
                        }
                    ],
                    "title": "Select the configuration of your machine:"
                }
            }
        ]
    },
    "target": "stella.lens"
}

pm.test('Check 320DL', () => {
    let jsonData = pm.response.json();
    for(let i=0;i<4;i++) {
        if (jsonData[0].message.content[1].data.knowledge[i].entity == responseSchema.message.content[1].data.knowledge[i].entity)
            pm.expect(jsonData[0].message.content[1].data.knowledge[i].value).to.equal(responseSchema.message.content[1].data.knowledge[i].value);
    }
   
});

my response body is:

[
    {
        "conversationId": "1ce08d79",
        "event": "UI",
        "message": {
            "content": [
                {
                    "command": "navigation",
                    "namespace": "ConversationTree-Options"
                },
                {
                    "command": "resultSet",
                    "data": {
                        "knowledge": [
                            {
                                "entity": "quotable_object",
                                "value": "bucket"
                            },
                            {
                                "entity": "bucket_class",
                                "value": "Excavator Bucket"
                            },
                            {
                                "entity": "equipment_model",
                                "value": "320d l"
                            }
                        ],
                        "options": [
                            {
                                "onClick": "/inform{\"equipment_configuration\": \"reach\"}",
                                "text": "reach"
                            },
                            {
                                "onClick": "/inform{\"equipment_configuration\": \"mass ex\"}",
                                "text": "mass ex"
                            }
                        ],
                        "title": "Select the configuration of your machine:"
                    }
                }
            ]
        },
        "target": "stella.lens"
    }
]

It’s more than likely to be the number of loops so if you changed 4 to 3 it would probably work. I suspect that it’s doing a final loop and looking for at property in an object that’s not there.

I think you need to take a look at your code though and refactor it, its getting a bit confusing to read and that will become even more difficult to debug.

What are you trying to achieve with the tests? What’s your end goal?