Hello there.
I´m working on my first project in the Quality Assurance section.
One of the things I have to do is write two tests: unit tests and functional tests.
My unite test code looks something like this:
describe("Unit Tests", function () {
describe("ConvertHandler functions", function () {
it("Should correctly read a whole number input.", function () {
assert.equal(convertHandler.getNum("10L"), 10);
});
});
My functional test (which I am working at right now) looks something like this:
describe("Functional Tests", function () {
describe("GET request to /api/convert", function () {
it("Convert a valid input such as 10L: GET request to /api/convert", function () {
chai
.request(server)
.get("/api/convert")
.query({ input: "10L" }) // /api/convert?input=10L
.end((err, res) => {
assert.equal(res.status, 200);
assert.equal(res.body.initNum, 10);
assert.equal(res.body.initUnit, "L");
assert.equal(res.body.returnNum, 2.64172);
assert.equal(res.body.returnUnit, "gal");
assert.equal(
res.body.string,
"10 liters converts to 2.64172 gallons"
);
});
});
});
});
I´m still struggling to understand some things related to Mocha/Chai but one of the things I don´t understand is when to use “done” in a callback function and then “done()” at the end. As you can see, I haven´t used this in my code, but I keep seeing this when I do research.
As far as I know, is used to make the function asychronous.
Do I need to make my code asychronous for some reason?
I’m not sure if I’m understanding this right, but I would make a function asynchronous to access a promise result, is that right?
I’m really confused with using or not “done()”, why I need to access the promise…