From 0843f9b44ebb8779151740188699dd2ce4997c38 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Fri, 7 Sep 2018 14:46:26 +0800 Subject: [PATCH 1/3] [jest] add missing matcher --- types/jest/index.d.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/types/jest/index.d.ts b/types/jest/index.d.ts index a9cbdbc1e3..75581cef8d 100644 --- a/types/jest/index.d.ts +++ b/types/jest/index.d.ts @@ -504,6 +504,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. */ From a0ac96829eeb23713c73d6ff4840a1e6527181af Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Fri, 7 Sep 2018 15:41:52 +0800 Subject: [PATCH 2/3] [jest] add test --- types/jest/jest-tests.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/types/jest/jest-tests.ts b/types/jest/jest-tests.ts index 801c6a5a78..a4ee07f1c8 100644 --- a/types/jest/jest-tests.ts +++ b/types/jest/jest-tests.ts @@ -513,6 +513,8 @@ describe("", () => { expect(jest.fn()).toBeCalled(); + expect(jest.fn()).toBeCalledTimes(1); + expect(jest.fn()).toBeCalledWith(); expect(jest.fn()).toBeCalledWith("jest"); expect(jest.fn()).toBeCalledWith({}, {}); From e23057b50f435f1298d3e0e2c37baf21219400ac Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Fri, 7 Sep 2018 16:09:20 +0800 Subject: [PATCH 3/3] [jest] add missing matcher --- types/jest/index.d.ts | 4 ++++ types/jest/jest-tests.ts | 3 +++ 2 files changed, 7 insertions(+) diff --git a/types/jest/index.d.ts b/types/jest/index.d.ts index 75581cef8d..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. */ diff --git a/types/jest/jest-tests.ts b/types/jest/jest-tests.ts index a4ee07f1c8..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, {});