jest mock use objects function code example
Example 1: jest mock class
test("es6 class", () => {
const SomeClass = jest.fn();
const mMock = jest.fn();
SomeClass.mockImplementation(() => {
return {
m: mMock
};
});
const some = new SomeClass();
some.m("a", "b");
expect(mMock.mock.calls).toEqual([["a", "b"]]);
});
Example 2: jest mock call
test("mock.calls", () => {
const mockFn = jest.fn();
mockFn(1, 2);
expect(mockFn.mock.calls).toEqual([[1, 2]]);
});