-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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: remove nullish params when resolving #1814
Conversation
✅ Deploy Preview for vue-router canceled.
|
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## main #1814 +/- ##
==========================================
- Coverage 90.86% 90.77% -0.09%
==========================================
Files 24 24
Lines 1116 1117 +1
Branches 347 348 +1
==========================================
Hits 1014 1014
Misses 63 63
- Partials 39 40 +1
... and 1 file with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot, it's indeed much better to write the tests without matchObject()
. Also, thanks for the detailed search made beforehand 🔍 , it really helps and it's a joy to review a PR like this! 😍
While testing this a bit, it made me wonder if it shouldn't cast the params to empty strings instead of removing them. This would it make consistent with router.resolve({ name: 'optional', params: { p: '' }})
. The other way around is not possible because a param can be intentionally empty (arguably not something people should use though). However, I feel like it's safer to keep the difference in this case. In practice, the user should test with !route.optionalParam
to check if an optional param is absent. I will have to make sure this is mentioned in the changelog
Hi ') <4.2
4.2
|
This is a bugfix. You can check the expected behavior in the test, among them, |
Introduction
This line appears in
router.ts
:The lines that follow update the contents of
targetParams
to remove nullish values, but that object is never actually used anywhere.Background
That code was introduced in change ebca15a. From what I can tell,
targetParams
was supposed to be used to buildmatcherLocation
on the lines that follow, but instead it is using the originalrawLocation.params
.The accompanying test also contains a problem. It is using
toMatchObject()
to verify that theparams
object is empty. Unfortunately,toMatchObject()
only checks properties that are present in the expectation, it won't fail for any extra properties that are present. So even though it appears to be verifying that theparams
is empty, that isn't really what it's doing. Theparams
object still contains thenull
andundefined
property values.Proposed Solution
I've assumed the intention is for the
null
andundefined
values to be removed, so I've adjusted the code accordingly.However, if the current behaviour is deemed correct then the alternative 'fix' would be to remove this section of the code, as it currently isn't doing anything.