forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 2
Guide: using-with-vue-router.md #3
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
Merged
MachinisteWeb
merged 3 commits into
vuejs-fr:working
from
Yaty:using-with-vue-router.md
Oct 23, 2017
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
# Using with Vue Router | ||
# Utilisation avec Vue Router | ||
|
||
## Installing Vue Router in tests | ||
## Installer Vue Router pour nos tests | ||
|
||
You should never install Vue Router on the Vue base constructor in tests. Installing Vue Router adds `$route` and `$router` as read-only properties on Vue prototype. | ||
Vous ne devez jamais installer Vue Router sur le constructeur de base de Vue pour vos tests. Installer Vue Router de cette manière ajoute `$route` et `$router` en tant que propriétés en lecture seule sur le prototype Vue. | ||
|
||
To avoid this, we can create a localVue, and install Vue Router on that. | ||
Pour éviter cela, on peut utiliser une localVue, et installer Vue Router dessus. | ||
|
||
```js | ||
import VueRouter from 'vue-router' | ||
|
@@ -17,21 +17,21 @@ shallow(Component, { | |
}) | ||
``` | ||
|
||
## Testing components that use `router-link` or `router-view` | ||
## Tester des composants qui utilisent `router-link` ou `router-view` | ||
|
||
When you install Vue Router, the `router-link` and `router-view` components are registered. This means we can use them anywhere in our application without needing to import them. | ||
Quand vous installez Vue Router, les composants `router-link` et `router-view` sont enregistrés. Cela veut dire que l'on peut les utiliser n'importe où dans notre application sans avoir besoin de les importer. | ||
|
||
When we run tests, we need to make these vue-router components available to the component we're mounting. There are two methods to do this. | ||
On doit donc rendre ces composants vue-router disponibles au composant que nous testons. Il y a deux méthodes pour cela. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Vue Router |
||
|
||
### Using stubs | ||
### Utiliser des stubs | ||
|
||
```js | ||
shallow(Component, { | ||
stubs: ['router-link', 'router-view'] | ||
}) | ||
``` | ||
|
||
### Installing Vue Router with localVue | ||
### Installer Vue Router avec localVue | ||
|
||
```js | ||
import VueRouter from 'vue-router' | ||
|
@@ -44,13 +44,13 @@ shallow(Component, { | |
}) | ||
``` | ||
|
||
## Mocking `$route` and `$router` | ||
## Simuler `$route` and `$router` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. et |
||
|
||
Sometimes you want to test that a component does something with parameters from the `$route` and `$router` objects. To do that, you can pass custom mocks to the Vue instance. | ||
Quelques fois, vous souhaitez tester qu'un composant réagisse correctement avec les paramètres des objets `$route` et `$router`. Pour cela, vous pouvez passer des imitations à l'instance de Vue. | ||
|
||
```js | ||
const $route = { | ||
path: '/some/path' | ||
path: '/un/super/chemin' | ||
} | ||
|
||
const wrapper = shallow(Component, { | ||
|
@@ -59,13 +59,13 @@ const wrapper = shallow(Component, { | |
} | ||
}) | ||
|
||
wrapper.vm.$router // /some/path | ||
wrapper.vm.$router // /un/super/chemin | ||
``` | ||
|
||
## Common gotchas | ||
## Trucs et astuces | ||
|
||
Installing Vue Router adds `$route` and `$router` as read-only properties on Vue prototype. | ||
Installer Vue Router ajoute `$route` et `$router` en tant que propriétés en lecture seule au prototype de Vue. | ||
|
||
This means any future tests that try to mock `$route` or `$router` will fail. | ||
Cela veut dire que n'importe quel futur test qui va essayer de modifier `$route` ou `$router` va échouer. | ||
|
||
To avoid this, never install Vue Router when you're running tests. | ||
Pour éviter cela, n'installez jamais Vue Router quand vous lancez vos tests. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
localVue