-
Notifications
You must be signed in to change notification settings - Fork 110
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
How to set initial router route? #15
Comments
Hi, if you look at the examples around routing the idea is that you find the link on the page and fire the click event on it. Would this suit your use case? |
@dfcook Oh, I do understand that's what x-testing-library is meant to do... Actually, let me change the question: How can I set the initial router route? Although according to this library I should be changing routes by clicking on the appropriate buttons, but I think I should be able to at least set the initial route, because it's a valid thing for a user to "land" on a certain page. |
I was thinking there must be some way of configuring the routes but it appears there isn't, a limitation of vue-router, see this issue: The obvious way to get around this is to expose the created router in the object returned from render but I'm not sure if that's a bit leaky given the aims of the dom-testing-library. Do you have any thoughts yourself on how you'd like it to work? I mean we could accept a default router property on the routes parameter and do a push immediately after rendering? |
@dfcook the way I imagined it is that in the |
I've pushed 0.16.0 which adds the constructed store and router to the configuration callback, this allows a router to be pushed before the component is rendered. /~https://github.com/testing-library/vue-testing-library/blob/master/src/__tests__/vue-router.js |
@dfcook thanks, that's great! But are you not worried that now one can have access to the router at any time by saving it to an outer variable from the init callback? I said the examples I said, because in those ways you would not have to expose the router. |
I suppose that's possible but I went for a middle path between dogmatism and pragmatism. This lets people control the initial setup then test against the DOM. If they want to start accessing the router directly then they're free to miss the point of such testing 😆 |
I want to be able to change the current vue-router route by pushing a new path, but I don't seem to get access to the router with the
render()
function.How am I supposed to change routes with this library?
EDIT: changed title from "How to change router route?"
The text was updated successfully, but these errors were encountered: