square.js
const multiply = require("./multiply");
const square = (n) => multiply(n, n);
module.exports = square;
multiply.js
const multiply = (x, y) => x * y;
module.exports = multiply;
square.test.js
const multiply = require("./multiply");
const square = require("./square");
jest.mock("./multiply");
test("square of 3 should be 9", () => {
multiply.mockResolvedValue(9);
expect(square(3)).toBe(9);
});
In the above test, I get the error: Expected: 9, Received: {}
I don't understand why this doesn't work, it works with axios
and this also works if I replace mockResolvedValue
with mockImplementation
like this: multiply.mockImplementation(n => 9)
Comments
Post a Comment