From b84793c2b2922408f9fd1b182c831719a34c21cd Mon Sep 17 00:00:00 2001 From: ibuibu Date: Sat, 12 Nov 2022 21:46:47 +0900 Subject: [PATCH] Add tests --- .../src/__tests__/toThrowMatchers.test.ts | 31 +++++++++++++++++++ packages/expect/src/__tests__/tsconfig.json | 3 ++ 2 files changed, 34 insertions(+) diff --git a/packages/expect/src/__tests__/toThrowMatchers.test.ts b/packages/expect/src/__tests__/toThrowMatchers.test.ts index ff0770008b93..f3c20c41a48e 100644 --- a/packages/expect/src/__tests__/toThrowMatchers.test.ts +++ b/packages/expect/src/__tests__/toThrowMatchers.test.ts @@ -278,6 +278,37 @@ 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', () => { + // less than v16 does not yet support Error.cause + if (Number(process.version.split('.')[0].slice(1)) < 16) { + expect(true).toBe(true); + } else { + jestExpect(() => { + throw new Error('good', {cause: errorA}); + }).not[toThrow](expected); + } + }); + }); + }); + 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": "../../"}] }