You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Failing matchers on ArrayBuffer, DataView, generators or Maps with boxed numbers throw a TypeError instead of a diff #16541
test('ArrayBuffer',()=>{expect(newUint8Array([1]).buffer).toStrictEqual(newUint8Array([2]).buffer);});test('ArrayBuffer toBe',()=>{expect(newArrayBuffer(1)).toBe(newArrayBuffer(1));});test('DataView',()=>{expect(newDataView(newArrayBuffer(1))).toEqual({x: 1});});test('generator',()=>{expect((function*(){})()).toEqual({x: 1});});test('Map with a boxed Number',()=>{expect(newMap([['n',newNumber(0)],['k',1]])).toEqual(newMap([['n',newNumber(0)],['k',2]]),);});
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.
Activity
fix(jest-matcher-utils): preserve built-in objects with internal slot…