@types/jest: Add inline snapshot matchers (#27258)

Add the following matchers:

- `toMatchInlineSnapshot`
- `toThrowErrorMatchingInlineSnapshot`
This commit is contained in:
Sebastian Sebald
2018-07-15 21:27:35 +02:00
committed by Ryan Cavanaugh
parent b8c4d1deb5
commit 56da96e652
2 changed files with 37 additions and 1 deletions

20
types/jest/index.d.ts vendored
View File

@@ -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 <https://asana.com>
// Ivo Stratev <https://github.com/NoHomey>
@@ -15,6 +15,7 @@
// Jeff Lau <https://github.com/UselessPickles>
// Andrew Makarov <https://github.com/r3nya>
// Martin Hochel <https://github.com/hotell>
// Sebastian Sebald <https://github.com/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<T extends {[P in keyof R]: Expect['any']}>(propertyMatchers: Partial<T>, 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 {

View File

@@ -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({});