diff --git a/CHANGELOG.md b/CHANGELOG.md index dc4bc7cd6bd8..f00da8fa096c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/packages/expect-utils/src/__tests__/utils.test.ts b/packages/expect-utils/src/__tests__/utils.test.ts index a563e9d9a860..7bf14ec27bd6 100644 --- a/packages/expect-utils/src/__tests__/utils.test.ts +++ b/packages/expect-utils/src/__tests__/utils.test.ts @@ -8,6 +8,7 @@ import {List, OrderedMap, OrderedSet, Record} from 'immutable'; import {stringify} from 'jest-matcher-utils'; +import {equals} from '../jasmineUtils'; import { arrayBufferEquality, emptyObject, @@ -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(); + }); }); diff --git a/packages/expect-utils/src/jasmineUtils.ts b/packages/expect-utils/src/jasmineUtils.ts index dcaebae99698..3f70f308054d 100644 --- a/packages/expect-utils/src/jasmineUtils.ts +++ b/packages/expect-utils/src/jasmineUtils.ts @@ -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;