mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
Merge pull request #26785 from Hotell/mh/jest/fix-throw-matchers
[jest]: add missing error instance type to toThrow
This commit is contained in:
Vendored
+2
-2
@@ -563,11 +563,11 @@ declare namespace jest {
|
||||
/**
|
||||
* Used to test that a function throws when it is called.
|
||||
*/
|
||||
toThrow(error?: string | Constructable | RegExp): R;
|
||||
toThrow(error?: string | Constructable | RegExp | Error): R;
|
||||
/**
|
||||
* If you want to test that a specific error is thrown inside a function.
|
||||
*/
|
||||
toThrowError(error?: string | Constructable | RegExp): R;
|
||||
toThrowError(error?: string | Constructable | RegExp | Error): R;
|
||||
/**
|
||||
* Used to test that a function throws a error matching the most recent snapshot when it is called.
|
||||
*/
|
||||
|
||||
@@ -556,15 +556,18 @@ describe("", () => {
|
||||
expect(true).toStrictEqual(false);
|
||||
expect({}).toStrictEqual({});
|
||||
|
||||
const errInstance = new Error();
|
||||
const willThrow = () => { throw new Error(); };
|
||||
expect(() => {}).toThrow();
|
||||
expect(() => { throw new Error(); }).toThrow("");
|
||||
expect(willThrow).toThrow("");
|
||||
expect(willThrow).toThrow(errInstance);
|
||||
expect(jest.fn()).toThrow(Error);
|
||||
expect(jest.fn(() => { throw new Error(); })).toThrow(/foo/);
|
||||
expect(jest.fn(willThrow)).toThrow(/foo/);
|
||||
|
||||
expect(() => {}).toThrowErrorMatchingSnapshot();
|
||||
expect(() => { throw new Error(); }).toThrowErrorMatchingSnapshot();
|
||||
expect(willThrow).toThrowErrorMatchingSnapshot();
|
||||
expect(jest.fn()).toThrowErrorMatchingSnapshot();
|
||||
expect(jest.fn(() => { throw new Error(); })).toThrowErrorMatchingSnapshot();
|
||||
expect(jest.fn(willThrow)).toThrowErrorMatchingSnapshot();
|
||||
|
||||
/* not */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user