Test Driven Development with Jest

Solution

//import sumconst { sum } = require("./sum");describe('Addition of Two Number functionality test',()=>{test("Add 1 + 2 should be 3", () => {expect(sum(1, 2)).toBe(3);
expect(sum(1,2)).toBeA(number);
});test("it should fail if string as parameter", () => {expect(sum("Hello", "World"))
.toEqual(Error("Expecting number type as parameter"));
});
});
test("Add 1+2 should be 3", () => {expect(sum(1, 2)).toBe(3);});
test("it should fail if string as parameter", () => {expect(sum("Hello", "World"))
.toEqual(Error("Expecting number type as parameter"));
const sum = (a, b) => {if (typeof a !== "number" || typeof b !== "number")return Error("Expecting number type as parameter");return a + b;};module.exports = { sum };
"scripts": {
"test": "jest"
},
All test cases passed
describe("Login Module for test cases", () => {it("should return the user if the name is valid", function(done) {request(app).post("/login").send({ username: "DAMMAK", password: "Adedamola" }).end(function(err, res) {expect(res.statusCode).toEqual(200);expect(res.text).toEqual(JSON.stringify({ username: "DAMMAK", password: "Adedamola" }));done();});});it("fails if login details is wrong", function(done) {request(app).post("/login").send({ username: "wrongUser", password: "wrongPass" }).end(function(err, res) {expect(res.statusCode).toEqual(400);done();});});it("fails if empty request data was sent", function(done) {request(app).post("/login").send({}).end(function(err, res) {expect(res.statusCode).toEqual(400);done();});});});