0

I have an express.js application where I am using supertest and should.js for my testing framework. I'm having trouble testing for values in an unordered array.

According to the should.js documentation, the .any function would work here. Any thoughts on how to get it to work would be greatly appreciated.

Expected Response

{data: [
  {username:"Test User 3", ...},
  {username:"Test User 6", ...}
]}

Attempted Validation Calls

response.body.data.any.username.should.equal("Test User 3");
response.body.data.any.username.should.equal("Test User 6");

Thanks in advance for your help!

Michael Merchant
  • 1,509
  • 2
  • 17
  • 28

1 Answers1

2

How about containDeep:

response.body.data.should.containDeep([{ username: "Test User 3" }]);
response.body.data.should.containDeep([{ username: "Test User 6" }]);
Timothy Strimple
  • 22,920
  • 6
  • 69
  • 76
  • Hey Tim, thanks for the pointer. I think you're missing array brackets around the objects. So it should come out to be: response.body.data.should.containDeep([{ username: "Test User 3" }]); If you don't mind updating, I can accept your answer :) – Michael Merchant Dec 12 '14 at 01:34
  • Right you are! Updated. – Timothy Strimple Dec 12 '14 at 02:04