Cypress - AssertionError: expected [ { payload: { data: [Object] } } ] to have property 'TotalMessageUI_ObjectClicked'

412 views Asked by At

I'm trying to verify TotalMessageUI_ObjectClicked contains a value other than NULL or 0

But I keep getting this error:

AssertionError: expected [ { payload: { data: [Object] } } ] to have property 'TotalMessageUI_ObjectClicked'

What is the best way to verify TotalMessageUI_ObjectClicked contains a value not NULL

{"data":{"actor":{"account":{"nrql":{"results":[{"TotalMessageUI_ObjectClicked":6}]}}}}}

Tried writing this:

expect(response.body).have.property('TotalMessageUI_ObjectClicked').to.not.be.oneOf([null, "",0]) 
2

There are 2 answers

4
jjhelguero On

You are not drilling down to the correct prop in your expected result.

expect(response.body[0].payload.data.actor.account.nrql.results[0])
  .have.property('TotalMessageUI_ObjectClicked')
  .to.not.be.oneOf([null, "",0])
0
Jan Nash On

The message

AssertionError: expected [ { payload: { data: [Object] } } ] to have ...

is telling you that response.body (the object you supplied) is actually [{ payload: { data: [Object] } } ].

So you can amend your test with that info, for example:

expect(response.body[0].payload.data.actor.account.nrql.results[0].TotalMessageUI_ObjectClicked)
  .to.not.be.oneOf([null, 0])