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",
"Buick",
"Cadillac",
"Chevrolet",
"Chrysler",
"Daewoo",
"Dodge",
"Ford",
"GMC",
"Honda",
"Hyundai",
"Infiniti",
"Isuzu",
"Jaguar",
"Jeep",
"Kia",
"Land Rover",
"Lexus",
"Lincoln",
"Mazda",
"Mercedes Benz",
"Mercury",
"Mitsubishi",
"Nissan",
"Oldsmobile",
"Plymouth",
"Pontiac",
"Porsche",
"Saab",
"Saturn",
"Subaru",
"Suzuki",
"Toyota",
"Volkswagen",
"Volvo"
]
}
}
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?
Aucun commentaire:
Enregistrer un commentaire