Skip to content

[Bug]: Failing matchers on ArrayBuffer, DataView, generators or Maps with boxed numbers throw a TypeError instead of a diff #16541

Description

@trackoor

Version

30.5.2

Steps to reproduce

  1. Save as repro.test.js:
test('ArrayBuffer', () => {
  expect(new Uint8Array([1]).buffer).toStrictEqual(new Uint8Array([2]).buffer);
});
test('ArrayBuffer toBe', () => {
  expect(new ArrayBuffer(1)).toBe(new ArrayBuffer(1));
});
test('DataView', () => {
  expect(new DataView(new ArrayBuffer(1))).toEqual({x: 1});
});
test('generator', () => {
  expect((function* () {})()).toEqual({x: 1});
});
test('Map with a boxed Number', () => {
  expect(new Map([['n', new Number(0)], ['k', 1]])).toEqual(
    new Map([['n', new Number(0)], ['k', 2]]),
  );
});
  1. npm i -D [email protected] && npx jest repro.test.js

Expected behavior

Each test fails with the usual expect(received).toStrictEqual(expected) / toBe / toEqual message and diff. pretty-format can print ArrayBuffer and DataView since #14290.

Actual behavior

Every test fails with an internal TypeError and no diff:

● ArrayBuffer
    TypeError: First argument to DataView constructor must be an ArrayBuffer
● ArrayBuffer toBe
    TypeError: First argument to DataView constructor must be an ArrayBuffer
● DataView
    TypeError: Method DataView.prototype.getInt8 called on incompatible receiver #<DataView>
● generator
    TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
● Map with a boxed Number
    TypeError: Number.prototype.toString requires that 'this' be a Number

Additional context

printDiffOrStringify copies both values with deepCyclicCopyReplaceable. Its builtInObject list does not include ArrayBuffer, DataView, boxed primitives or generators, so they are rebuilt with Object.create(proto) and lose their internal slots; pretty-format then calls methods that need those slots. packages/jest-matcher-utils, expect-utils, pretty-format and jest-diff are unchanged on main (7261444) since v30.5.2.

Environment

System:
    OS: Linux 6.1 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
    CPU: (64) x64 Intel(R) Xeon(R) CPU @ 2.80GHz
  Binaries:
    Node: 26.13.0
    npm: 11.20.0
  npmPackages:
    jest: ^30.5.2 => 30.5.2

Credit: https://ucsbplse.github.io/

Activity

  1. added a commit that references this issue on Nov 12, 2026
    65e17b3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions