mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 20:40:20 +00:00
Jest: Added Generic for "toMatchObject" function (#35033)
* Add generic to toMatchObject * Cover feedback from @wsmd
This commit is contained in:
committed by
Wesley Wigham
parent
6d0dc421d7
commit
53230a10b3
Vendored
+19
-1
@@ -18,6 +18,7 @@
|
||||
// Sebastian Sebald <https://github.com/sebald>
|
||||
// Andy <https://github.com/andys8>
|
||||
// Antoine Brault <https://github.com/antoinebrault>
|
||||
// Jeroen Claassens <https://github.com/favna>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 3.0
|
||||
|
||||
@@ -757,8 +758,25 @@ declare namespace jest {
|
||||
toMatch(expected: string | RegExp): R;
|
||||
/**
|
||||
* Used to check that a JavaScript object matches a subset of the properties of an object
|
||||
*
|
||||
* Optionally, you can provide an object to use as Generic type for the expected value.
|
||||
* This ensures that the matching object matches the structure of the provided object-like type.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* type House = {
|
||||
* bath: boolean;
|
||||
* bedrooms: number;
|
||||
* kitchen: {
|
||||
* amenities: string[];
|
||||
* area: number;
|
||||
* wallColor: string;
|
||||
* }
|
||||
* };
|
||||
*
|
||||
* expect(desiredHouse).toMatchObject<House>(...standardHouse, kitchen: {area: 20}) // wherein standardHouse is some base object of type House
|
||||
*/
|
||||
toMatchObject(expected: {} | any[]): R;
|
||||
toMatchObject<E extends {} | any[]>(expected: E): 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.
|
||||
|
||||
@@ -830,6 +830,8 @@ describe("", () => {
|
||||
expect({ abc: "def" }).toMatchObject({ abc: "def" });
|
||||
expect({}).toMatchObject([{}, {}]);
|
||||
expect({ abc: "def" }).toMatchObject([{ abc: "def" }, { invalid: "property" }]);
|
||||
expect({abc: "def"}).toMatchObject<{abc: string}>({abc: "def"});
|
||||
expect([{abc: 'def'}, {abc: 'def'}]).toMatchObject<[{abc: string}, {abc: string}]>([{abc: 'def'}, {abc: 'def'}]);
|
||||
|
||||
expect({}).toMatchSnapshot();
|
||||
expect({}).toMatchSnapshot("snapshotName");
|
||||
|
||||
Reference in New Issue
Block a user