diff --git a/packages/expect/src/__tests__/toThrowMatchers.test.ts b/packages/expect/src/__tests__/toThrowMatchers.test.ts index ff0770008b93..1d7a14cad011 100644 --- a/packages/expect/src/__tests__/toThrowMatchers.test.ts +++ b/packages/expect/src/__tests__/toThrowMatchers.test.ts @@ -278,6 +278,58 @@ describe.each(['toThrowError', 'toThrow'] as const)('%s', toThrow => { }); }); + describe('error message and cause', () => { + const errorA = new Error('A'); + const errorB = new Error('B', {cause: errorA}); + const expected = new Error('good', {cause: errorB}); + + describe('pass', () => { + test('isNot false', () => { + jestExpect(() => { + throw new Error('good', {cause: errorB}); + })[toThrow](expected); + }); + + test('isNot true, incorrect message', () => { + jestExpect(() => { + throw new Error('bad', {cause: errorB}); + }).not[toThrow](expected); + }); + + test('isNot true, incorrect cause', () => { + jestExpect(() => { + throw new Error('good', {cause: errorA}); + }).not[toThrow](expected); + }); + }); + + describe('fail', () => { + test('isNot false, incorrect message', () => { + expect(() => + jestExpect(() => { + throw new Error('bad', {cause: errorB}); + })[toThrow](expected), + ).toThrowErrorMatchingSnapshot(); + }); + + test('isNot false, incorrect cause', () => { + expect(() => + jestExpect(() => { + throw new Error('good', {cause: errorA}); + })[toThrow](expected), + ).toThrowErrorMatchingSnapshot(); + }); + + test('isNot true, hoge', () => { + expect(() => + jestExpect(() => { + throw new Error('good', {cause: errorB}); + }).not[toThrow]({cause: errorB, message: 'good'}), + ).toThrowErrorMatchingSnapshot(); + }); + }); + }); + describe('asymmetric', () => { describe('any-Class', () => { describe('pass', () => { diff --git a/packages/expect/src/__tests__/tsconfig.json b/packages/expect/src/__tests__/tsconfig.json index dd1bca103251..a13f31174db4 100644 --- a/packages/expect/src/__tests__/tsconfig.json +++ b/packages/expect/src/__tests__/tsconfig.json @@ -1,5 +1,8 @@ { "extends": "../../../../tsconfig.test.json", + "compilerOptions": { + "lib": ["es2022"] + }, "include": ["./**/*"], "references": [{"path": "../../"}] }