fix(jest): add missing error instance type to toThrow

Closes #26756
This commit is contained in:
Martin Hochel
2018-06-24 09:54:31 +02:00
parent e6b8a914b6
commit d2077a5a58
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 */