URLSearchParams deep equal not working
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 112
- Forks
- 45
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 1
Description
I'm trying to test if my URLSearchParams are correct with the to.deep.equal option but it returns true (is equal) when it shouldn't.
See the running code at https://stackblitz.com/edit/node-qx7qra?file=index.test.js
Let's assume that we're testing this function:
function getIncorrectParams() {
return new URLSearchParams({
from: '2020',
to: '2021',
ids: ['abc-1'],
});
}
If I write:
test('via string', () => {
expect(getIncorrectParams().toString()).not.to.equal(
new URLSearchParams({
from: '2020',
to: '2021',
ids: ['abc-1', 'abc-2'],
}).toString()
);
});
It correctly notices that the strings are not the same, good. But as soon as I remove the toString and test with:
test('via deep equal', () => {
expect(getIncorrectParams()).not.to.deep.equal(
new URLSearchParams({
from: '2020',
to: '2021',
ids: ['abc-1', 'abc-2'],
})
);
});
It claims that the assertion failed because the two objects are "equal". Note if you actually go ahead and run the example, the debug output clearly shows that there are differences!
And the deep.equal property works if I use "normal" object. See this example where I convert the URLSearchParams to a "plain object" first:
test('deep equal plain objects', () => {
expect(Object.fromEntries(getIncorrectParams().entries())).not.to.deep.equal({
from: '2020',
to: '2021',
ids: ['abc-1', 'abc-2'],
});
});
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the linked StackBlitz reproduction in index.test.js and compare the URLSearchParams deep-equality assertion with the string and plain-object cases. Trace how deep-eql inspects URLSearchParams, then add a regression test showing that differing parameter values are not equal; done means the test correctly distinguishes the two instances.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100