Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/runtime/test_runner/expect/toBeArrayOfSize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub(crate) fn to_be_array_of_size(

let not = this.flags.get().not();
let mut pass = value.js_type().is_array()
&& i32::try_from(value.get_length(global)?).unwrap() == size.to_int32();
&& value.get_length(global)? as i64 == size.to_int64();
Comment thread
robobun marked this conversation as resolved.

if not {
pass = !pass;
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/test_runner/expect/toHaveBeenCalledTimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
)));
}

let times = arguments[0].coerce::<i32>(global)?;
let times = arguments[0].to_int64();

Check warning on line 26 in src/runtime/test_runner/expect/toHaveBeenCalledTimes.rs

View check run for this annotation

Claude / Claude Code Review

toHaveReturnedTimes still has the is_uint32_as_any_int + coerce::<i32> mismatch this PR removed here

🟡 nit: `toHaveReturnedTimes` still has the same `is_uint32_as_any_int()` guard + `coerce::<i32>` narrowing this PR just removed here — `expect(fn).toHaveReturnedTimes(3_000_000_000)` passes the guard but wraps to `-1_294_967_296` and silently compares against a negative count (see `src/runtime/test_runner/expect/toHaveReturned.rs:50-57`). It doesn't panic so it's lower-severity than the headline fix, but since this PR already invoked the "fix the whole class" rule once for `toHaveBeenCalledTimes
Comment thread
robobun marked this conversation as resolved.

let mut pass = i32::try_from(calls.get_length(global)?).unwrap() == times;
let mut pass = calls.get_length(global)? as i64 == times;

let not = this.flags.get().not();
if not {
Expand Down
4 changes: 4 additions & 0 deletions test/js/bun/test/jest-extended.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ describe("jest-extended", () => {
expect({}).not.toBeArrayOfSize(1);
expect("").not.toBeArrayOfSize(1);
expect(0).not.toBeArrayOfSize(1);
// Array length can be up to 2^32-1, which exceeds i32 range.
expect(new Array(3_000_000_000)).toBeArrayOfSize(3_000_000_000);
expect(new Array(3_000_000_000)).not.toBeArrayOfSize(5);
expect(new Array(2 ** 32 - 1)).toBeArrayOfSize(2 ** 32 - 1);
});

// test('toIncludeAllMembers()')
Expand Down
9 changes: 9 additions & 0 deletions test/js/bun/test/mock-fn.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,15 @@ describe("mock()", () => {
expect(fn).not.toHaveBeenNthCalledWith(5, 1);
});

test("toHaveBeenCalledTimes with calls.length > i32 max", () => {
const fn = jest.fn();
// Array length can be up to 2^32-1; the matcher must not panic on the narrowed count.
fn.mock.calls.length = 3_000_000_000;
expect(fn).not.toHaveBeenCalledTimes(5);
expect(fn).toHaveBeenCalledTimes(3_000_000_000);
expect(() => expect(fn).toHaveBeenCalledTimes(5)).toThrow();
});

it("no segmentation fault when passing jest.fn into another jest.fn, issue#5900", () => {
function foo() {
return true;
Expand Down
Loading