I have this code:
const mocha = require("mocha");
const assert = require("assert");
describe("saving records", function (done) {
it("Saves a record to the database", function (done) {
let mx = false;
setTimeout(() => {
mx = false; //#### note this line
}, 6000);
done();
assert(mx === true);
});
});
I am not sure why, but mocha gives a test pass in the terminal that says:
saving records ✓ Saves a record to the database
1 passing (30ms)
Question no.1 : Why is the test passing at this point
The next weird thing is: It doesn't even wait for 6 seconds seconds before the test passes. Since, I've used done
parameter, Question no. 2: shouldn't it wait until the execution is done?
Have I misinterpreted some information?