Skip to content
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: comparing different URL objects now return false #14672

Merged
merged 5 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- `[jest-circus, jest-expect, jest-snapshot]` Pass `test.failing` tests when containing failing snapshot matchers ([#14313](https://github.com/jestjs/jest/pull/14313))
- `[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]` 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 @@ -17,6 +17,7 @@ import {
subsetEquality,
typeEquality,
} from '../utils';
import { equals } from "../jasmineUtils";

describe('getPath()', () => {
test('property exists', () => {
Expand Down Expand Up @@ -578,9 +579,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