Skip to content

Commit

Permalink
fix: comparing different URL objects now return false (#14672)
Browse files Browse the repository at this point in the history
  • Loading branch information
tr1ckydev authored Nov 3, 2023
1 parent 544a4b8 commit 6cbba98
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- `[jest-config]` Make sure to respect `runInBand` option ([#14578](https://github.com/facebook/jest/pull/14578))
- `[@jest/expect-utils]` Fix comparison of `DataView` ([#14408](https://github.com/jestjs/jest/pull/14408))
- `[@jest/expect-utils]` [**BREAKING**] exclude non-enumerable in object matching ([#14670](https://github.com/jestjs/jest/pull/14670))
- `[@jest/expect-utils]` Fix comparison of `URL` ([#14672](https://github.com/jestjs/jest/pull/14672))
- `[jest-leak-detector]` Make leak-detector more aggressive when running GC ([#14526](https://github.com/jestjs/jest/pull/14526))
- `[jest-runtime]` Properly handle re-exported native modules in ESM via CJS ([#14589](https://github.com/jestjs/jest/pull/14589))
- `[jest-util]` Make sure `isInteractive` works in a browser ([#14552](https://github.com/jestjs/jest/pull/14552))
Expand Down
15 changes: 14 additions & 1 deletion packages/expect-utils/src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import {List, OrderedMap, OrderedSet, Record} from 'immutable';
import {stringify} from 'jest-matcher-utils';
import {equals} from '../jasmineUtils';
import {
arrayBufferEquality,
emptyObject,
Expand Down Expand Up @@ -623,9 +624,21 @@ describe('arrayBufferEquality', () => {
expect(arrayBufferEquality(a, b)).toBeTruthy();
});

test('returns false when given matching DataView', () => {
test('returns false when given non-matching DataView', () => {
const a = new DataView(Uint8Array.from([1, 2, 3]).buffer);
const b = new DataView(Uint8Array.from([3, 2, 1]).buffer);
expect(arrayBufferEquality(a, b)).toBeFalsy();
});

test('returns true when given matching URL', () => {
const a = new URL('https://jestjs.io/');
const b = new URL('https://jestjs.io/');
expect(equals(a, b)).toBeTruthy();
});

test('returns false when given non-matching URL', () => {
const a = new URL('https://jestjs.io/docs/getting-started');
const b = new URL('https://jestjs.io/docs/getting-started#using-babel');
expect(equals(a, b)).toBeFalsy();
});
});
3 changes: 3 additions & 0 deletions packages/expect-utils/src/jasmineUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ function eq(
// RegExps are compared by their source patterns and flags.
case '[object RegExp]':
return a.source === b.source && a.flags === b.flags;
// URLs are compared by their href property which contains the entire url string.
case '[object URL]':
return a.href === b.href;
}
if (typeof a !== 'object' || typeof b !== 'object') {
return false;
Expand Down

0 comments on commit 6cbba98

Please sign in to comment.