Comments (7)
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 😆
from vue-testing-library.
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?
from vue-testing-library.
@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.
from vue-testing-library.
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?
from vue-testing-library.
@dfcook the way I imagined it is that in the configurationCb
, a function would be exposed that would allow me to change the route only 1 time, and that too only for the duration of configurationCb
(it would stop working afterward). That would ensure that I could only change the route initially, but not later.
...or maybe you could have the same thing, but as a "route" string needed to be passed to a property of RenderOptions
. I can see that react-testing-library uses a route property: https://github.com/kentcdodds/react-testing-library/blob/master/examples/__tests__/react-router.js#L38
from vue-testing-library.
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
from vue-testing-library.
@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.
from vue-testing-library.
Related Issues (20)
- Form missing emitted data when submit
- Vuex store's mutations are lost when passing options.store in Vue2
- Support for custom queries
- Tests fail when using injecting custom components globally
- Tsx with storybook fails when using defineComponents HOT 1
- Unable to make mocking or stubs HOT 3
- ESM export
- Is this a valid test? HOT 1
- Problem using `testing-library` with vue <script setup> HOT 1
- Multi-root node components aren't cleaned properly up after each test HOT 2
- Doesn't cleanup with vitest by default HOT 1
- Rendering of child components does not work with @vue/compat
- How do I test the hook of beforeRouteEnter in the version of vue 2.6.14
- Passing data to a component using the composition api HOT 1
- Testing with vue-18n and script setup HOT 4
- Teleport containing element with v-if does not render at all
- Type safe render options (props, slots, emits)
- Unable to use with vue 3.3.x
- 8.0.0 makes it impossible to run with vitest and no global afterEach HOT 1
- after manually calling the umount method, cleanupAtWrapper will report an error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue-testing-library.