diff --git a/types/jest/index.d.ts b/types/jest/index.d.ts index 68fab8c1b8..fa1cb4074a 100644 --- a/types/jest/index.d.ts +++ b/types/jest/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Jest 23.1 +// Type definitions for Jest 23.3 // Project: http://facebook.github.io/jest/ // Definitions by: Asana // Ivo Stratev @@ -15,6 +15,7 @@ // Jeff Lau // Andrew Makarov // Martin Hochel +// Sebastian Sebald // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -661,6 +662,18 @@ declare namespace jest { * Check out [the Snapshot Testing guide](http://facebook.github.io/jest/docs/snapshot-testing.html) for more information. */ toMatchSnapshot(snapshotName?: string): R; + /** + * This ensures that a value matches the most recent snapshot with property matchers. + * Instead of writing the snapshot value to a .snap file, it will be written into the source code automatically. + * Check out [the Snapshot Testing guide](http://facebook.github.io/jest/docs/snapshot-testing.html) for more information. + */ + toMatchInlineSnapshot(propertyMatchers: Partial, snapshot?: string): R; + /** + * This ensures that a value matches the most recent snapshot with property matchers. + * Instead of writing the snapshot value to a .snap file, it will be written into the source code automatically. + * Check out [the Snapshot Testing guide](http://facebook.github.io/jest/docs/snapshot-testing.html) for more information. + */ + toMatchInlineSnapshot(snapshot?: string): R; /** * Ensure that a mock function has returned (as opposed to thrown) at least once. */ @@ -689,6 +702,11 @@ declare namespace jest { * Used to test that a function throws a error matching the most recent snapshot when it is called. */ toThrowErrorMatchingSnapshot(): R; + /** + * Used to test that a function throws a error matching the most recent snapshot when it is called. + * Instead of writing the snapshot value to a .snap file, it will be written into the source code automatically. + */ + toThrowErrorMatchingInlineSnapshot(snapshot?: string): R; } interface Constructable { diff --git a/types/jest/jest-tests.ts b/types/jest/jest-tests.ts index b502644cdd..9eb14a5751 100644 --- a/types/jest/jest-tests.ts +++ b/types/jest/jest-tests.ts @@ -617,6 +617,15 @@ describe("", () => { date: new Date(), }).toMatchSnapshot({ one: expect.any(Number), date: expect.any(Date) }); + expect({}).toMatchInlineSnapshot(); + expect({}).toMatchInlineSnapshot("snapshot"); + expect({ abc: "def" }).toMatchInlineSnapshot({ abc: expect.any(String) }, "snapshot"); + expect({ + one: 1, + two: "2", + date: new Date(), + }).toMatchInlineSnapshot({ one: expect.any(Number), date: expect.any(Date) }); + expect(jest.fn()).toReturn(); expect(jest.fn()).toReturnTimes(0); @@ -641,6 +650,15 @@ describe("", () => { expect(jest.fn()).toThrowErrorMatchingSnapshot(); expect(jest.fn(willThrow)).toThrowErrorMatchingSnapshot(); + expect(() => {}).toThrowErrorMatchingInlineSnapshot(); + expect(() => {}).toThrowErrorMatchingInlineSnapshot('Error Message'); + expect(willThrow).toThrowErrorMatchingInlineSnapshot(); + expect(willThrow).toThrowErrorMatchingInlineSnapshot('Error Message'); + expect(jest.fn()).toThrowErrorMatchingInlineSnapshot(); + expect(jest.fn()).toThrowErrorMatchingInlineSnapshot('Error Message'); + expect(jest.fn(willThrow)).toThrowErrorMatchingInlineSnapshot(); + expect(jest.fn(willThrow)).toThrowErrorMatchingInlineSnapshot('Error Message'); + /* not */ expect({}).not.toEqual({});