Skip to content

Commit 89c99c4

Browse files
authored
fix: toBeWithin fails with bigints (closes #769) (#771)
1 parent 549cf9f commit 89c99c4

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

.changeset/shaky-rings-study.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'jest-extended': patch
3+
---
4+
5+
toBeWithin fails with bigints

src/matchers/toBeWithin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export function toBeWithin(actual: unknown, start: number, end: number) {
22
// @ts-expect-error OK to have implicit any for this.utils
33
const { printReceived, printExpected, matcherHint } = this.utils;
44

5-
const pass = typeof actual === 'number' && actual >= start && actual < end;
5+
const pass = (typeof actual === 'number' || typeof actual === 'bigint') && actual >= start && actual < end;
66

77
return {
88
pass,

test/matchers/toBeWithin.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ describe('.toBeWithin', () => {
77
expect(1).toBeWithin(1, 3);
88
});
99

10+
test('passes when given bigint number is within the given bounds of start (inclusive) and end (exclusive)', () => {
11+
expect(BigInt(1)).toBeWithin(1, 3);
12+
});
13+
1014
test('fails when given number is not within the given bounds of start (inclusive) and end (exclusive)', () => {
1115
expect(() => expect(3).toBeWithin(1, 3)).toThrowErrorMatchingSnapshot();
1216
});

0 commit comments

Comments
 (0)