mock a component jest code example
Example 1: jest mock call
test("mock.calls", () => {
const mockFn = jest.fn();
mockFn(1, 2);
expect(mockFn.mock.calls).toEqual([[1, 2]]);
});
Example 2: jest mock instance
test("mock.instances", () => {
const mockFn = jest.fn();
const a = new mockFn();
const b = new mockFn();
mockFn.mock.instances[0] === a;
mockFn.mock.instances[1] === b;
});