I'm attempting to write a mocha test dynamically, rather than write an expect for each item in a res.body.result. I have a json response like this:
{
"ok": true,
"result": {
"year": "2000",
"makes": [
"Acura",
"Audi",
"BMW"
]
}
}
and instead of writing this for each of the makes:
describe('Decode VIN', function (){
it('should return 200 response', function (done){
api.get('/makes_year?year=2000')
.set('Accept', 'application.json')
.expect(200)
.end(function(err, res) {
expect(res.body.ok).to.equal(true)
expect(res.body.result.year).to.equal("2000")
expect(res.body.result.makes).to.equal("Acura")
expect(res.body.result.makes).to.equal("Audi")
done();
})
});
});
How can I make this iteratively?
edit: I tried declaring the expectedMakes inside the describe statement and out. For brevity, this is only one of the two.
var expectedMakes = [
"Acura",
"Audi",
"BMW"
];
describe('Makes By Year', function (){
it('should return 200 response, body.ok, and an array of vehicle makes', function (done){
api.get('/makes_year?year=2000')
.set('Accept', 'application.json')
.expect(200)
.end(function(err, res) {
expect(res.body.ok).to.equal(true)
expect(res.body.result.year).to.equal("2000")
expect(res.body.result.makes).to.equal(expectedMakes)
done();
})
});
});
I get this result:
Uncaught AssertionError: expected [ Array(37) ] to equal [ Array(37) ]
+ expected - actual