I want to test the return value of a mock function in jest.
In following code i want to mock fs module's mkdirSync function
const fs = require("fs");
describe("Testing mock fs.mkdirSync", () => {
fs.mkdirSync = jest.fn().mockReturnValue(5);
fs.mkdirSync("./apple");
it("fs.mkdirSync must have been called", () => {
expect(fs.mkdirSync).toHaveBeenCalled();
});
//This test fails with TypeError: Cannot read property '0' of undefined
it("fs.mkdirSync last return value must be 5", () => {
expect(fs.mkdirSync.mock.results[0].value).toBe(5);
});
});
Second test fails with TypeError: Cannot read property '0' of undefined
"scripts": { ... "test": "jest" }
. The code is in a .test.js file. all in a project created with create-react-app. – Jemi Salo