You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/testing.md
+24Lines changed: 24 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -87,6 +87,30 @@ describe('actions', () => {
87
87
})
88
88
```
89
89
90
+
If your environment uses [Jest](http://jestjs.io/):
91
+
```js
92
+
importshopfrom'../api/shop'
93
+
94
+
describe('actions', () => {
95
+
it('getAllProducts', () => {
96
+
constcommit=jest.fn()
97
+
conststate= {}
98
+
99
+
let getProductsSpy =jest.spyOn(shop, 'getProducts')
100
+
getProductsSpy.mockImplementation(() => {
101
+
return [ /* mocked response */]
102
+
});
103
+
104
+
actions.getAllProducts({ commit, state })
105
+
106
+
expect(commit.args).to.deep.equal([
107
+
['REQUEST_PRODUCTS'],
108
+
['RECEIVE_PRODUCTS', { /* mocked response */ }]
109
+
])
110
+
})
111
+
})
112
+
```
113
+
90
114
## Testing Getters
91
115
92
116
If your getters have complicated computation, it is worth testing them. Getters are also very straightforward to test for the same reason as mutations.
0 commit comments