-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat: setParams #43
feat: setParams #43
Conversation
Codecov Report
@@ Coverage Diff @@
## v2 #43 +/- ##
==========================================
+ Coverage 97.91% 97.93% +0.02%
==========================================
Files 5 5
Lines 96 97 +1
Branches 10 11 +1
==========================================
+ Hits 94 95 +1
Misses 2 2
Continue to review full report at Codecov.
|
e76b797
to
f7927af
Compare
@posva I amended the commit with your feedback:
|
src/router.ts
Outdated
@@ -174,12 +181,17 @@ export function createRouterMock(options: RouterMockOptions = {}): RouterMock { | |||
return pendingNavigation || Promise.resolve() | |||
} | |||
|
|||
function setParams(params: RouteParams) { | |||
router.currentRoute.value = { ...router.currentRoute.value, params } |
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.
shouldn't router.currentRoute.value = router.resolve({ params })
work too? It will also allow using RouteParamsRaw
as params
and allow numbers while still casting them to strings
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.
I can definitely use router.resolve({ params })
👍
But can I use RouteParamsRaw
? It looks like it's not publicly exported
vue-router.d.ts
:
export declare type RouteParams = Record<string, RouteParamValue | RouteParamValue[]>;
declare type RouteParamsRaw = Record<string, RouteParamValueRaw | RouteParamValueRaw[]>;
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.
I will export it
src/router.ts
Outdated
@@ -40,6 +41,12 @@ export interface RouterMock extends Router { | |||
* isn't any. | |||
*/ | |||
getPendingNavigation(): ReturnType<Router['push']> | |||
|
|||
/** | |||
* Sets the params of the current route |
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.
* Sets the params of the current route | |
* Sets the params of the current route without triggering a navigation. | |
* Use `router.push()` if you want to trigger a navigation instead. | |
* |
@cexbrayat I released a new version of vue router that exports the missing types, it should be good to rebase on v2 and add the missing types 🙂 |
Introduces a new function `setParams`, allowing to set the parameters of the current route: ```js it('should display the user details', async () => { getRouter().setParams({ userId: 12 }) const wrapper = mount(UserDetails) // test... }) ``` Refs posva#42
f7927af
to
0dddc3b
Compare
@posva Done! It now uses |
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! I will add a few local changes
I added a few changes that should help with usage at 6d2829d I think we should use them for setQuery and setHash too |
Introduces a new function
setParams
, allowing to set the parameters of the current route:Refs #42
What kind of change does this PR introduce? (check at least one)
Does this PR introduce a breaking change? (check one)
If yes, please describe the impact and migration path for existing applications:
The PR fulfills these requirements:
fix #xxx[,#xxx]
, where "xxx" is the issue number)If adding a new feature, the PR's description includes:
Other information:
@posva If that looks good, I'll do the same for
setQuery
andsetHash