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

Route props functionality in router.mock #137

Open
dospunk opened this issue Nov 23, 2021 · 2 comments
Open

Route props functionality in router.mock #137

dospunk opened this issue Nov 23, 2021 · 2 comments

Comments

@dospunk
Copy link

dospunk commented Nov 23, 2021

What problem is this solving

When using the router mock as it currently is, we cannot test the prop changing functionality (described here in the vue docs).

More specifically to my situation: I have two routes that load the same component with a different prop, and the component itself contains links to both routes. I want to test some functionality that happens when the prop changes. I'd like to keep it as close to real use as possible, and in a real use situation the flow of events would go something like User clicks link -> vue-router pushes the given route -> vue-router updates the component's prop -> a watcher is triggered. I could easily use VTU's setProps function, but that would skip the first two steps, which isn't ideal.

Proposed solution

When I use the mocked router's push function, I would like for it to update the current component's props if there is a props option given in the route.

In order to not break existing code this could be added as an option similar to runInComponentGuards, which would be disabled by default.

Describe alternatives you've considered

As I stated above it's easy enough to use setProps, but that adds another step away from real use.

@posva posva added this to To do in Roadmap Nov 26, 2021
@andrei-gheorghiu
Copy link

andrei-gheorghiu commented Feb 21, 2022

From the outside it looks like you want to test vue-router itself. While that might have some utility in an e2e test, you should probably limit your unit tests to the components' inputs and outputs. That's what UTs are for.

Note you also have router.setQuery and router.setParams helpers available on the mock instance, allowing you to test any watchers set on route.

@dospunk
Copy link
Author

dospunk commented Mar 7, 2022

It's more so that I want to test behavior triggered by vue-router's functionality. You're right that it falls somewhat outside the scope of a unit test, but the tests that I'm writing aren't strict unit tests (it gets very hard to stick to straight unit testing when trying to test whole pages I've found).

I will check out the setQuery and setParams functions, hopefully one of those will help me get the functionality I need! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Roadmap
To do
Development

No branches or pull requests

2 participants