-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: properly compare TypedArray
s of all types
#15178
Conversation
✅ Deploy Preview for jestjs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
@@ -670,37 +670,55 @@ describe('arrayBufferEquality', () => { | |||
test('returns false when given non-matching buffers', () => { | |||
const a = Uint8Array.from([2, 4]).buffer; | |||
const b = Uint16Array.from([1, 7]).buffer; | |||
expect(arrayBufferEquality(a, b)).not.toBeTruthy(); | |||
expect(arrayBufferEquality(a, b)).toBe(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was a separate bug - it returned undefined
, not false
since Uint16Array.from([1, 7]).buffer instanceOf ArrayBuffer
for some reason is `false.
@@ -413,9 +415,12 @@ export const arrayBufferEquality = ( | |||
let dataViewA = a; | |||
let dataViewB = b; | |||
|
|||
if (a instanceof ArrayBuffer && b instanceof ArrayBuffer) { | |||
if (isArrayBuffer(a) && isArrayBuffer(b)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
This partially addresses #15176, in that it
toEqual
call drop from 500ms to 100ms (due to us not using the iterator, but iterating "normally" which is 5x faster)toStrictEqual
it drops to 3-4 ms, comparable tolodash
implementation (without the changes in this PR, there is no difference betweentoEqual
andtoStrictEqual
)There might be a case for us to include
arrayBufferEquality
in the custom matchers we use intoEqual
here:jest/packages/expect/src/matchers.ts
Lines 626 to 629 in 76514a8
In that case,
toEqual
also drops down to 3-4 ms runtime.Test plan
Tests added