-
-
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
router.push could be a simple mock functions by default? #41
Comments
I disagree with this one. I often need query params updated on the url. What if we could by default ignore named route locations so query params and hash are still populated? Meaning that the vue router mock push method calls internally |
Can you give me an example, I'm not sure I understand what you mean? |
An example is a search page with search params in url as query params, the params are used in the search but are an implementation detail and should not get in the way of testing the search component. |
Do you mean when you test the search component? In that case, wouldn't simple utils like Even if I'm misunderstanding your use-case, wouldn't most unit tests be simple |
The push is done internally. The test clicks on the button to search |
Ok so let's go back to what you were proposing
Sounds good to me. The resolve phase could even be skipped if the mock router has been created with no routes? |
It shouldn't be skipped because it normalizes the route location and also to simulate how the router changes the current route by affecting the whole route also, and this should be respected because it won't trigger the same watchers, making a test fail while the actual code works |
Adds a try/catch around the route resolution to simplify testing scenarios where the developers use `router.push({name: 'hey'})` and do not want to declare the corresponding route, as they just want to check if `push` was called. Fixes posva#41
I followed your idea and opened #53 I tried a patched version in our projects, and it does simplify our tests quite a bit 👍 |
Adds a try/catch around the route resolution to simplify testing scenarios where the developers use `router.push({name: 'hey'})` and do not want to declare the corresponding route, as they just want to check if `push` was called. Fixes posva#41
Co-authored-by: Eduardo San Martin Morote <[email protected]>
What problem is this solving
For a component doing a navigation with
router.push({ name: 'home' });
on an action, our associated unit test usually does a simple assertion like the following:Using
vue-router-mock
, we can simplify the test a bit by usingcreateRouterMock
:but the mock router created tries to really resolve the navigation and throws:
Proposed solution
Would it be possible to have a simpler router mock that just have mock functions by default?
Most use cases would probably not need a real navigation to be resolved and triggered.
Or maybe that could be an option?
Describe alternatives you've considered
It's of course possible to spy on
getRouter().push
but I feel that this should be the default.The text was updated successfully, but these errors were encountered: