In my test, I am passing an object that has two boolean values (among other values) to my API. I am then testing that the object was stored correctly in my database. The response should be exactly the same as the input, except that MySql stores booleans as integers.
I would like to test all of the fields without repetitive code, so I have written this:
const validChannel = {
id: `${new Date().getTime()}`,
major_nbr: 2,
minor_nbr: 1,
delivery: 'ATSC1',
display_nbr: '2.10',
opt_in: true,
visible: true,
callsign: 'TEST',
};
const channel = api.get();
Object.keys(validChannel).forEach((k) => {
expect(channel[k]).to.equal(validChannel[k]);
});
This works great, except that Mocha uses strict comparison, so 1 != true. How can I make this work while still keeping it compact?
question from:
https://stackoverflow.com/questions/65853259/loose-equality-in-mocha 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…