Skip to content

Commit 1d8e1ee

Browse files
authored
docs: update highlights when mocking real router
1 parent 4b3df07 commit 1d8e1ee

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

docs/fr/guide/advanced/vue-router.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ console.warn node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:39
187187

188188
Les composants `<router-link>` et `<router-view>` ne sont pas trouvés. Nous devons installer Vue Router&nbsp;! Comme Vue Router est un plugin, nous l'installons en utilisant l'option de `mount`&nbsp;: `global.plugins`&nbsp;:
189189

190-
```js {10,11,12}
190+
```js {12,13,14}
191191
import { mount } from '@vue/test-utils';
192192
import { createRouter, createWebHistory } from 'vue-router';
193193
import { routes } from "@/router"; // Cet import devrait pointer vers votre fichier de configuration des routes.
@@ -218,7 +218,7 @@ Le `warning` n'est pas très explicite. En fait, cela est lié au fait que **Vue
218218

219219
Vue Router fournit une fonction `isReady` qui nous informe lorsque le routeur est prêt. Nous pouvons alors l'`await` pour nous assurer que la navigation initiale a eu lieu.
220220

221-
```js {11,12}
221+
```js {13,14}
222222
import { mount } from '@vue/test-utils';
223223
import { createRouter, createWebHistory } from 'vue-router';
224224
import { routes } from "@/router";
@@ -247,7 +247,7 @@ Le test passe enfin&nbsp;! Cela a été assez laborieux, mais désormais nous no
247247

248248
Maintenant, allons sur `/posts` et assurons-nous que le routage fonctionne comme prévu&nbsp;:
249249

250-
```js {19,20}
250+
```js {21,22}
251251
import { mount } from '@vue/test-utils';
252252
import { createRouter, createWebHistory } from 'vue-router';
253253
import { routes } from "@/router";
@@ -288,7 +288,7 @@ Une fois de plus, en raison de la nature asynchrone de Vue Router 4, nous devons
288288

289289
Cependant, il n'y a pas de `hook` `hasNavigated` sur lequel nous pouvons `await`. Une alternative est d'utiliser la fonction `flushPromises` exportée de Vue Test Utils&nbsp;:
290290

291-
```js {1,20}
291+
```js {1,22}
292292
import { mount, flushPromises } from '@vue/test-utils';
293293
import { createRouter, createWebHistory } from 'vue-router';
294294
import { routes } from "@/router";
@@ -317,7 +317,7 @@ test('routing', async () => {
317317

318318
Cela passe. Super&nbsp;! Cependant, c'est très laborieux - et cela concerne une petite application triviale. C'est pour cette raison que l'utilisation d'un routeur simulé est une approche courante lors des tests de composants Vue avec Vue Test Utils. Si vous préférez continuer à utiliser un routeur réel, gardez à l'esprit que chaque test doit utiliser son propre instance du routeur de cette manière&nbsp;:
319319

320-
```js {1,20}
320+
```js {1,22}
321321
import { mount, flushPromises } from '@vue/test-utils';
322322
import { createRouter, createWebHistory } from 'vue-router';
323323
import { routes } from "@/router";

docs/guide/advanced/vue-router.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ console.warn node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:39
187187

188188
The `<router-link>` and `<router-view>` component are not found. We need to install Vue Router! Since Vue Router is a plugin, we install it using the `global.plugins` mounting option:
189189

190-
```js {10,11,12}
190+
```js {12,13,14}
191191
import { mount } from '@vue/test-utils'
192192
import { createRouter, createWebHistory } from 'vue-router'
193193
import { routes } from "@/router" // This import should point to your routes file declared above
@@ -218,7 +218,7 @@ Although it's not entirely clear from the warning, it's related to the fact that
218218

219219
Vue Router provides an `isReady` function that tell us when router is ready. We can then `await` it to ensure the initial navigation has happened.
220220

221-
```js {11,12}
221+
```js {13,14}
222222
import { mount } from '@vue/test-utils'
223223
import { createRouter, createWebHistory } from 'vue-router'
224224
import { routes } from "@/router"
@@ -247,7 +247,7 @@ The test is now passing! It was quite a bit of work, but now we make sure the ap
247247

248248
Now let's navigate to `/posts` and make sure the routing is working as expected:
249249

250-
```js {19,20}
250+
```js {21,22}
251251
import { mount } from '@vue/test-utils'
252252
import { createRouter, createWebHistory } from 'vue-router'
253253
import { routes } from "@/router"
@@ -288,7 +288,7 @@ Again, due to Vue Router 4's new asynchronous nature, we need to `await` the rou
288288

289289
In this case, however, there is no _hasNavigated_ hook we can await on. One alternative is to use the `flushPromises` function exported from Vue Test Utils:
290290

291-
```js {1,20}
291+
```js {1,22}
292292
import { mount, flushPromises } from '@vue/test-utils'
293293
import { createRouter, createWebHistory } from 'vue-router'
294294
import { routes } from "@/router"
@@ -317,7 +317,7 @@ test('routing', async () => {
317317

318318
It _finally_ passes. Great! This is all very manual, however - and this is for a tiny, trivial app. This is the reason using a mocked router is a common approach when testing Vue components using Vue Test Utils. In case you prefer to keep using a real router, keep in mind that each test should use it's own instance of the router like so:
319319

320-
```js {1,20}
320+
```js {1,19}
321321
import { mount, flushPromises } from '@vue/test-utils'
322322
import { createRouter, createWebHistory } from 'vue-router'
323323
import { routes } from "@/router"

0 commit comments

Comments
 (0)