Jestでモック関数が正しい引数で呼び出されたことを確認する
code: mock-function-called-test.ts
const mockCallback = jest.fn(x => 42 + x);
forEach(0, 1, mockCallback);
// The mock function is called twice
expect(mockCallback.mock.calls.length).toBe(2);
// The first argument of the first call to the function was 0
expect(mockCallback.mock.calls00).toBe(0);
// The first argument of the second call to the function was 1
expect(mockCallback.mock.calls10).toBe(1);
// The return value of the first call to the function was 42
expect(mockCallback.mock.results0.value).toBe(42);
参考: https://jestjs.io/docs/ja/mock-functions#モック関数を利用する
#Jest
#snippet