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

[Bug]: Jest reports different URL objects as PASS. #14399

Closed
tr1ckydev opened this issue Aug 10, 2023 · 8 comments · Fixed by #14672
Closed

[Bug]: Jest reports different URL objects as PASS. #14399

tr1ckydev opened this issue Aug 10, 2023 · 8 comments · Fixed by #14672

Comments

@tr1ckydev
Copy link
Contributor

Version

29.6.2-dev

Steps to reproduce

test('url test', () => {
    expect(new URL("https://jestjs.io/")).toEqual(new URL("https://jestjs.io/docs/getting-started"));
});

Expected behavior

I expect this test to FAIL.

Actual behavior

Jest reports this test as PASS.

Additional context

I have fixed this bug in this pr(#14398) which happens primarily in Node.js environment.

Environment

System:
    OS: Linux 6.4 CachyOS Linux
    CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700H
  Binaries:
    Node: 20.5.0 - /usr/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 9.8.1 - /usr/bin/npm
  npmPackages:
    jest: ^29.6.2 => 29.6.2
@mrazauskas
Copy link
Contributor

which happens primarily in Node.js environment.

Hm.. Are you sure? The following fails as expected:

/**
 * @jest-environment node
 */

test("url test", () => {
  expect(new URL("https://jestjs.io/")).toEqual(
    new URL("https://jestjs.io/docs/getting-started"),
  );
});

But this will pass (and that is wrong):

/**
 * @jest-environment jsdom
 */

test("url test", () => {
  expect(new URL("https://jestjs.io/")).toEqual(
    new URL("https://jestjs.io/docs/getting-started"),
  );
});

@mrazauskas
Copy link
Contributor

mrazauskas commented Aug 10, 2023

By the way, if you are happy about the solution in the fix you suggested, why not to compare only href properties in the test?

/**
 * @jest-environment jsdom
 */

test("url test", () => {
  expect(new URL("https://jestjs.io/").href).toEqual(
    new URL("https://jestjs.io/docs/getting-started").href,
  );
});

The thing is that what you suggest is a breaking change. Users might be interested to compare the whole object and that should be possible.

For example, if Error object is passed to current .toEqual() implementation, only message props will be compared. Unfortunately that does not satisfy all use cases. E.g. see #13232 (and there are more similar complains).

@tr1ckydev
Copy link
Contributor Author

Hm.. Are you sure? The following fails as expected:

Just tried it, it results PASS for me in node.js

By the way, if you are happy about the solution in the fix you suggested, why not to compare only href properties in the test?

That's the workaround im doing for now, but still its a bug if it reports PASS when its actually not.

@mrazauskas
Copy link
Contributor

Just tried it, it results PASS for me in node.js

Does not reproduce for me. Could you create a reproduction repo so I could see the whole setup? Or just wait and perhaps someone else will figure out what is going on.

@MasterGordon
Copy link

MasterGordon commented Sep 5, 2023

It really depends on the node version, for me on node 20 it always passes and on node 14 the tests fail because the url/hrefs don't match.

@github-actions
Copy link

github-actions bot commented Oct 5, 2023

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@haines
Copy link

haines commented Nov 1, 2023

I ran into this on Node 20 with the toStrictEqual matcher: #14668. Repro: https://github.com/haines/jest-url-strict-equality.

@github-actions github-actions bot removed the Stale label Nov 1, 2023
@SimenB SimenB linked a pull request Nov 3, 2023 that will close this issue
Copy link

github-actions bot commented Dec 4, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants