Skip to content

Commit

Permalink
fix: enable "showDiff" for "toThrow(CustomErrorClass)"
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Jan 20, 2024
1 parent 9d3a7de commit c6e0412
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 0 additions & 1 deletion packages/expect/src/jest-expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,6 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
`expected error not to be instance of ${name}`,
expected,
thrown,
false,
)
}

Expand Down
13 changes: 13 additions & 0 deletions test/core/test/__snapshots__/jest-expect.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,16 @@ stringContainingCustom<ll>
"message": "expected error to match asymmetric matcher",
}
`;
exports[`asymmetric matcher error 23`] = `
{
"actual": "[Error: hello]",
"diff": "- Expected:
[Function MyError1]
+ Received:
[Error: hello]",
"expected": "[Function MyError1]",
"message": "expected error to be instance of MyError1",
}
`;
8 changes: 8 additions & 0 deletions test/core/test/jest-expect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,14 @@ it('asymmetric matcher error', () => {
snapshotError(() => expect(() => {
throw new Error('hello')
}).toThrow((expect as any).stringContainingCustom('ll')))

// error constructor
class MyError1 extends Error {}
class MyError2 extends Error {}

snapshotError(() => expect(() => {
throw new MyError2('hello')
}).toThrow(MyError1))
})

it('timeout', () => new Promise(resolve => setTimeout(resolve, 500)))

0 comments on commit c6e0412

Please sign in to comment.