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]: unable to match URL query parameters with nodejs v19.8.1 #14012

Closed
akornatskyy opened this issue Mar 16, 2023 · 6 comments
Closed

[Bug]: unable to match URL query parameters with nodejs v19.8.1 #14012

akornatskyy opened this issue Mar 16, 2023 · 6 comments

Comments

@akornatskyy
Copy link

Version

29.5.0

Steps to reproduce

const x = jest.fn();

const url = new URL('http://localhost:8080/x');
url.searchParams.set('a', '1');

x(url);

expect(x).toBeCalledWith(new URL('http://localhost:8080/x?a=1'));

Expected behavior

it doesn't fail with nodejs 19.7.0

Actual behavior

    @@ -9,6 +9,13 @@
          "port": "8080",
          "protocol": "http:",
          "search": "?a=1",
          "username": "",
        },
    +   Symbol(query): URLSearchParams {
    +     Symbol(query): Array [
    +       "a",
    +       "1",
    +     ],
    +     Symbol(context): [Circular],
    +   },
      }

Additional context

No response

Environment

linux
@koshic
Copy link

koshic commented Mar 16, 2023

nodejs/node#46308 ?

@akornatskyy
Copy link
Author

akornatskyy commented Apr 11, 2023

+ nodejs 19.9.0

@github-actions
Copy link

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.

@github-actions github-actions bot added the Stale label May 11, 2023
@SimenB
Copy link
Member

SimenB commented May 11, 2023

The test in the OP passes for me using Node 19.7. However, using the JSDOM test environment fails. I'd say this is a bug with JSDOM's URL, which comes from whatwg-url.

// file.js
const whatWgURL = require('whatwg-url');

const nodeUrl = new URL('https://example.org/');
const wgUrl = new whatWgURL.URL('https://example.org/');

logSymbols(nodeUrl, wgUrl);

nodeUrl.searchParams.set('a', 'b');
wgUrl.searchParams.set('a', 'b');

logSymbols(nodeUrl, wgUrl);

logSymbols(
  new URL('https://example.org/?a=b'),
  new whatWgURL.URL('https://example.org/?a=b'),
);

function logSymbols(first, second) {
  // https://github.com/jestjs/jest/blob/bc26cd79e60b7bf29d854293f0f011936fda1a5a/packages/expect-utils/src/jasmineUtils.ts#L211-L223
  const firstSymbols = Object.getOwnPropertySymbols(first).filter(
    symbol => Object.getOwnPropertyDescriptor(first, symbol).enumerable,
  );

  const secondSymbols = Object.getOwnPropertySymbols(second).filter(
    symbol => Object.getOwnPropertyDescriptor(second, symbol).enumerable,
  );

  console.log({ firstSymbols, secondSymbols });
}
$ node -v
v19.7.0
$ node file.js
{ firstSymbols: [ Symbol(context), Symbol(query) ], secondSymbols: [] }
{
  firstSymbols: [ Symbol(context), Symbol(query) ],
  secondSymbols: [ Symbol(SameObject caches) ]
}
{ firstSymbols: [ Symbol(context), Symbol(query) ], secondSymbols: [] }
$ node -v
v20.1.0
$ node file.js
{ firstSymbols: [], secondSymbols: [] }
{ firstSymbols: [], secondSymbols: [ Symbol(SameObject caches) ] }
{ firstSymbols: [], secondSymbols: [] }

You can see the symbols are different in the whatwg URL when searchParams are used, unlike what happens with the node core URL.

If the symbols are not enumerable, that would also fix it.

(for Jest's comparison to pass it doesn't need to match between whatwg and Node, but it needs to be internally consistent)

@SimenB SimenB closed this as not planned Won't fix, can't repro, duplicate, stale May 11, 2023
@SimenB
Copy link
Member

SimenB commented May 11, 2023

I'd recommend comparing .href instead of the instances, btw.

@github-actions
Copy link

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 Jun 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants