Skip to content

Commit b9b860f

Browse files
committed
docs(testing): add in simplistic Jest example in case it can be helpful
1 parent 4af52e9 commit b9b860f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

docs/guide/testing.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,30 @@ describe('actions', () => {
8787
})
8888
```
8989

90+
If your environment uses [Jest](http://jestjs.io/):
91+
```js
92+
import shop from '../api/shop'
93+
94+
describe('actions', () => {
95+
it('getAllProducts', () => {
96+
const commit = jest.fn()
97+
const state = {}
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+
90114
## Testing Getters
91115

92116
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

Comments
 (0)