jest mock name 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 mockname
test("mockName", () => {
const mockFn = jest.fn().mockName("mockedFunction");
mockFn(); // comment me
expect(mockFn).toHaveBeenCalled();
});