0

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]) 
Ferando
  • 141
  • 8

2 Answers2

4

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])
Jan Nash
  • 168
  • 9
0

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])
jjhelguero
  • 2,281
  • 5
  • 13
  • Makes sense, but when I drilled down further, even with your code I get an error at 'actor' `TypeError: Cannot read properties of undefined (reading 'actor')` – testerJeff Mar 16 '23 at 23:29
  • Also the response is also a Payload, not sure if that is affecting it too. I tried `expect(response.body.payload.data.actor.account.nrql.results[0]).have.property('TotalMessageUI_ObjectClicked').to.not.be.oneOf([null, "",0])` but same issue still too. Cannot read properties of undefined (reading 'data') – testerJeff Mar 17 '23 at 00:09
  • Looks like `response.body` is an array. You can try with `response.body[0].payload.data.actor.account.nrql.results[0]`. – jjhelguero Mar 17 '23 at 00:14
  • Nice I updated the answer to reflect that. – jjhelguero Mar 17 '23 at 02:00