Merge pull request #26785 from Hotell/mh/jest/fix-throw-matchers

[jest]: add missing error instance type to toThrow
This commit is contained in:
Paul van Brenk
2018-06-25 13:40:41 -07:00
committed by GitHub
2 changed files with 9 additions and 6 deletions
+2 -2
View File
@@ -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.
*/
+7 -4
View File
@@ -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 */