diff --git a/src/runtime/test_runner/expect/toBeArrayOfSize.rs b/src/runtime/test_runner/expect/toBeArrayOfSize.rs index 464e5bdd543b..08c3e2ef8082 100644 --- a/src/runtime/test_runner/expect/toBeArrayOfSize.rs +++ b/src/runtime/test_runner/expect/toBeArrayOfSize.rs @@ -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(); if not { pass = !pass; diff --git a/src/runtime/test_runner/expect/toHaveBeenCalledTimes.rs b/src/runtime/test_runner/expect/toHaveBeenCalledTimes.rs index c903e69ae195..060d673a9317 100644 --- a/src/runtime/test_runner/expect/toHaveBeenCalledTimes.rs +++ b/src/runtime/test_runner/expect/toHaveBeenCalledTimes.rs @@ -23,9 +23,9 @@ pub(crate) fn to_have_been_called_times( ))); } - let times = arguments[0].coerce::(global)?; + let times = arguments[0].to_int64(); - 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 { diff --git a/test/js/bun/test/jest-extended.test.js b/test/js/bun/test/jest-extended.test.js index 4cf2a29e7abd..2ab04a8d161b 100644 --- a/test/js/bun/test/jest-extended.test.js +++ b/test/js/bun/test/jest-extended.test.js @@ -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()') diff --git a/test/js/bun/test/mock-fn.test.js b/test/js/bun/test/mock-fn.test.js index 7f6a244d9806..ff8a36f2a90b 100644 --- a/test/js/bun/test/mock-fn.test.js +++ b/test/js/bun/test/mock-fn.test.js @@ -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;