From dfe05a96d68413ba114ff0bef1d0a95803f2fcf4 Mon Sep 17 00:00:00 2001 From: Andy Date: Thu, 12 Jul 2018 09:49:45 +0200 Subject: [PATCH] @types/jest: toMatchSnapshot updated for property matchers (#27170) --- types/jest/index.d.ts | 7 ++++++- types/jest/jest-tests.ts | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/types/jest/index.d.ts b/types/jest/index.d.ts index e32b9f05f0..68fab8c1b8 100644 --- a/types/jest/index.d.ts +++ b/types/jest/index.d.ts @@ -394,7 +394,7 @@ declare namespace jest { * * @param actual The value to apply matchers against. */ - (actual: any): Matchers; + (actual: T): Matchers; /** * Matches anything but null or undefined. You can use it inside `toEqual` or `toBeCalledWith` instead * of a literal value. For example, if you want to check that a mock function is called with a @@ -651,6 +651,11 @@ declare namespace jest { * Used to check that a JavaScript object matches a subset of the properties of an object */ toMatchObject(expected: {} | any[]): R; + /** + * This ensures that a value matches the most recent snapshot with property matchers. + * Check out [the Snapshot Testing guide](http://facebook.github.io/jest/docs/snapshot-testing.html) for more information. + */ + toMatchSnapshot(propertyMatchers: Partial, snapshotName?: string): R; /** * This ensures that a value matches the most recent snapshot. * Check out [the Snapshot Testing guide](http://facebook.github.io/jest/docs/snapshot-testing.html) for more information. diff --git a/types/jest/jest-tests.ts b/types/jest/jest-tests.ts index c54ebc3369..b502644cdd 100644 --- a/types/jest/jest-tests.ts +++ b/types/jest/jest-tests.ts @@ -610,6 +610,12 @@ describe("", () => { expect({}).toMatchSnapshot(); expect({}).toMatchSnapshot("snapshotName"); + expect({ abc: "def" }).toMatchSnapshot({ abc: expect.any(String) }, "snapshotName"); + expect({ + one: 1, + two: "2", + date: new Date(), + }).toMatchSnapshot({ one: expect.any(Number), date: expect.any(Date) }); expect(jest.fn()).toReturn();