diff --git a/types/jest/index.d.ts b/types/jest/index.d.ts index a9cbdbc1e3..b663e37076 100644 --- a/types/jest/index.d.ts +++ b/types/jest/index.d.ts @@ -481,6 +481,10 @@ declare namespace jest { * If you know how to test something, `.not` lets you test its opposite. */ not: Matchers; + /** + * Ensure that a mock function is called with specific arguments on an Nth call. + */ + nthCalledWith(nthCall: number, ...params: any[]): R; /** * Ensure that the nth call to a mock function has returned a specified value. */ @@ -504,6 +508,10 @@ declare namespace jest { * Ensures that a mock function is called. */ toBeCalled(): R; + /** + * Ensures that a mock function is called an exact number of times. + */ + toBeCalledTimes(expected: number): R; /** * Ensure that a mock function is called with specific arguments. */ diff --git a/types/jest/jest-tests.ts b/types/jest/jest-tests.ts index 801c6a5a78..2de3cadfd4 100644 --- a/types/jest/jest-tests.ts +++ b/types/jest/jest-tests.ts @@ -504,6 +504,9 @@ describe("", () => { expect(jest.fn()).lastReturnedWith("jest"); expect(jest.fn()).lastReturnedWith({}); + expect(jest.fn()).nthCalledWith(0, "jest"); + expect(jest.fn()).nthCalledWith(1, {}); + expect(jest.fn()).nthReturnedWith(0, "jest"); expect(jest.fn()).nthReturnedWith(1, {}); @@ -513,6 +516,8 @@ describe("", () => { expect(jest.fn()).toBeCalled(); + expect(jest.fn()).toBeCalledTimes(1); + expect(jest.fn()).toBeCalledWith(); expect(jest.fn()).toBeCalledWith("jest"); expect(jest.fn()).toBeCalledWith({}, {});