Skip to content

Commit 4dc4b9d

Browse files
committed
Traduction de testing.md
Signed-off-by: Bruno Lesieur <[email protected]>
1 parent 540d633 commit 4dc4b9d

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

docs/en/book.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"pluginsConfig": {
55
"edit-link": {
66
"base": "https://github.com/vuejs/vuex/tree/dev/docs",
7-
"label": "Edit This Page"
7+
"label": "Éditer cette page"
88
},
99
"github": {
1010
"url": "https://github.com/vuejs/vuex/"

docs/en/testing.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Testing
1+
# Tests
22

3-
The main parts we want to unit test in Vuex are mutations and actions.
3+
Les parties principales que l'on veut couvrir par des tests unitaires en Vuex sont les mutations et les actions.
44

5-
### Testing Mutations
5+
### Tester les mutations
66

7-
Mutations are very straightforward to test, because they are just functions that completely rely on their arguments. One trick is that if you are using ES2015 modules and put your mutations inside your `store.js` file, in addition to the default export, you can also export the mutations as a named export:
7+
Les mutations sont très simples à tester, puisque ce sont de simples fonctions qui se basent uniquement sur leurs arguments. Une astuce est que si vous utilisez les modules ES2015 et mettez vos mutations dans votre fichier `store.js`, en plus de l'export par défaut, vous pouvez également exporter vos mutations avec un export nommé :
88

99
``` js
1010
const state = { ... }
@@ -18,7 +18,7 @@ export default new Vuex.Store({
1818
})
1919
```
2020

21-
Example testing a mutation using Mocha + Chai (you can use any framework/assertion libraries you like):
21+
Exemple de test de mutation utilisant Mocha + Chai (vous pouvez utiliser n'importe quel framework/bibliothèque d'assertion selon votre préférence) :
2222

2323
``` js
2424
// mutations.js
@@ -47,11 +47,11 @@ describe('mutations', () => {
4747
})
4848
```
4949

50-
### Testing Actions
50+
### Tester les actions
5151

52-
Actions can be a bit more tricky because they may call out to external APIs. When testing actions, we usually need to do some level of mocking - for example, we can abstract the API calls into a service and mock that service inside our tests. In order to easily mock dependencies, we can use webpack and [inject-loader](https://github.com/plasticine/inject-loader) to bundle our test files.
52+
Les actions sont un peu plus compliquées car elles peuvent faire appel à des APIs externes. Lorsque l'on teste des actions, on a souvent besoin de faire du mocking &mdash; par exemple, on peut abstraire l'appel API dans un service et mocker ce service dans nos tests. Afin de mocker facilement les dépendances, on peut utiliser webpack et [inject-loader](https://github.com/plasticine/inject-loader) pour regrouper nos fichiers de test.
5353

54-
Example testing an async action:
54+
Exemple de test d'une action asynchrone :
5555

5656
``` js
5757
// actions.js
@@ -86,7 +86,7 @@ const actions = actionsInjector({
8686
})
8787

8888
// helper for testing action with expected mutations
89-
const testAction = (action, payload, state, expectedMutations, done) => {
89+
const testAction = (action, args, state, expectedMutations, done) => {
9090
let count = 0
9191

9292
// mock commit
@@ -109,7 +109,7 @@ const testAction = (action, payload, state, expectedMutations, done) => {
109109
}
110110

111111
// call the action with mocked store and arguments
112-
action({ commit, state }, payload)
112+
action({ commit, state }, ...args)
113113

114114
// check if no mutations should have been dispatched
115115
if (expectedMutations.length === 0) {
@@ -120,19 +120,19 @@ const testAction = (action, payload, state, expectedMutations, done) => {
120120

121121
describe('actions', () => {
122122
it('getAllProducts', done => {
123-
testAction(actions.getAllProducts, null, {}, [
123+
testAction(actions.getAllProducts, [], {}, [
124124
{ type: 'REQUEST_PRODUCTS' },
125125
{ type: 'RECEIVE_PRODUCTS', payload: { /* mocked response */ } }
126126
], done)
127127
})
128128
})
129129
```
130130

131-
### Testing Getters
131+
### Tester les getters
132132

133-
If your getters have complicated computation, it is worth testing them. Getters are also very straightforward to test as same reason as mutations.
133+
Si vos getters font des calculs compliqués, il peut être judicieux de les tester. Les getters sont également très simples à tester, pour les mêmes raisons que les mutations.
134134

135-
Example testing a getter:
135+
Exemple de test d'un getter :
136136

137137
``` js
138138
// getters.js
@@ -175,13 +175,13 @@ describe('getters', () => {
175175
})
176176
```
177177

178-
### Running Tests
178+
### Lancer les tests
179179

180-
If your mutations and actions are written properly, the tests should have no direct dependency on Browser APIs after proper mocking. Thus you can simply bundle the tests with webpack and run it directly in Node. Alternatively, you can use `mocha-loader` or Karma + `karma-webpack` to run the tests in real browsers.
180+
Si vos mutations et actions sont écrites comme il se doit, les tests ne devraient pas avoir de dépendance directe sur les APIs navigateur après un mocking préalable. Cela signifie que vous pouvez simplement regrouper les tests avec webpack et les lancer directement dans Node. De façon alternative, vous pouvez utiliser `mocha-loader` ou Karma + `karma-webpack` afin d'effectuer les tests dans des vrais navigateurs.
181181

182-
#### Running in Node
182+
#### Lancer dans Node
183183

184-
Create the following webpack config (together with proper [`.babelrc`](https://babeljs.io/docs/usage/babelrc/)):
184+
Créez la configuration webpack suivante (ainsi que le fichier [`.babelrc`](https://babeljs.io/docs/usage/babelrc/) qui correspond) :
185185

186186
``` js
187187
// webpack.config.js
@@ -203,20 +203,20 @@ module.exports = {
203203
}
204204
```
205205

206-
Then:
206+
Puis :
207207

208208
``` bash
209209
webpack
210210
mocha test-bundle.js
211211
```
212212

213-
#### Running in Browser
213+
#### Lancer dans un navigateur
214214

215-
1. Install `mocha-loader`
216-
2. Change the `entry` from the webpack config above to `'mocha!babel!./test.js'`.
217-
3. Start `webpack-dev-server` using the config
218-
4. Go to `localhost:8080/webpack-dev-server/test-bundle`.
215+
1. Installez `mocha-loader`
216+
2. Changez l'option `entry` de la configuration webpack ci-dessus pour `'mocha!babel!./test.js'`.
217+
3. Démarrez `webpack-dev-server` en utilisant cette configuration.
218+
4. Pointez votre navigateur sur `localhost:8080/webpack-dev-server/test-bundle`.
219219

220-
#### Running in Browser with Karma + karma-webpack
220+
#### Lancer dans un navigateur avec Karma + karma-webpack
221221

222-
Consult the setup in [vue-loader documentation](http://vue-loader.vuejs.org/en/workflow/testing.html).
222+
Consultez la procédure sur la [documentation vue-loader](http://vue-loader.vuejs.org/en/workflow/testing.html).

0 commit comments

Comments
 (0)