If you don't want to use a for loop or the chai-things library, you can use the deep equal expectation to compare the entire array in a single assertion:
const expect = require('chai').expect;
const myObj = [ {fName: 'abc', lName: 'xyz'}, {fName: 'efg', lName: 'lmn'} ];
describe('Test Suite', () => {
it('MyObj Test', function() {
expect(myObj).to.eql([ {fName: 'abc', lName: 'xyz'}, {fName: 'efg', lName: 'lmn'}]);
});
});
If you change the second object and run the tests, you'll see a very specific error:
AssertionError: expected [ Array(2) ] to deeply equal [ Array(2) ]
+ expected - actual
"lName": "xyz"
}
{
"fName": "efg"
- "lName": "lmn"
+ "lName": "lmn2"
}
]
Or you must write all expectations explicitily:
expect(myObj).to.be.an('array');
expect(myObj[0]).to.have.property('fName');
expect(myObj[0]).to.have.property('lName');
expect(myObj[1]).to.have.property('fName');
expect(myObj[1]).to.have.property('lName');
// and so on...