Skip to content

Commit a3d1e2e

Browse files
fix: bigint cause error (#15702)
1 parent f4296d2 commit a3d1e2e

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## main
22

3+
### Fixes
4+
5+
- `[expect]` Fix `bigint` error ([#15702](https://github.com/jestjs/jest/pull/15702))
6+
37
## 30.0.4
48

59
### Features

packages/expect/src/__tests__/toThrowMatchers.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,15 @@ describe('toThrow', () => {
328328
});
329329
});
330330

331+
test('isNot false, cause is bigint', () => {
332+
jestExpect(() => {
333+
throw new Error('Message', {cause: 0n});
334+
}).toThrow({
335+
cause: 0n,
336+
message: 'Message',
337+
});
338+
});
339+
331340
test('isNot false, cause is object', () => {
332341
jestExpect(() => {
333342
throw new Error('Message', {

packages/expect/src/toThrowMatchers.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,10 @@ function createMessageAndCause(error: Error) {
486486
if (seen.has(value)) return;
487487
seen.add(value); // stop circular references
488488
}
489-
return value === undefined ? String(undefined) : value;
489+
if (typeof value === 'bigint' || value === undefined) {
490+
return String(value);
491+
}
492+
return value;
490493
});
491494
}
492495

0 commit comments

Comments
 (0)