Using shouldjs to check values in an unordered array

478 views Asked by At

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!

1

There are 1 answers

2
Timothy Strimple On BEST ANSWER

How about containDeep:

response.body.data.should.containDeep([{ username: "Test User 3" }]);
response.body.data.should.containDeep([{ username: "Test User 6" }]);