create mock functions jest code example
Example 1: how to mock a library in jest
import randomColor from "randomcolor";
jest.mock("randomColor", () => {
return {
randomColor: () => {
return mockColor('#123456');
}
}
});
let mockColor = jest.fn();
Example 2: jest mock mockname
test("mockName", () => {
const mockFn = jest.fn().mockName("mockedFunction");
mockFn(); // comment me
expect(mockFn).toHaveBeenCalled();
});