Skip to content

Commit a893204

Browse files
πŸ“ Writing docs
1 parent 97fc715 commit a893204

File tree

1 file changed

+101
-8
lines changed

1 file changed

+101
-8
lines changed

β€ŽREADME.mdβ€Ž

Lines changed: 101 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,104 @@
1-
# Vue Test Actions
1+
<p>
2+
<a href="https://npmjs.com/package/vue-test-actions"><img src="https://img.shields.io/npm/v/vue-test-actions.svg?style=flat" alt="NPM version"></a>
3+
<a href="https://npmjs.com/package/vue-test-actions"><img src="https://img.shields.io/npm/dm/vue-test-actions.svg?style=flat" alt="NPM downloads"></a>
4+
<a href="https://www.npmjs.com/package/vue-test-actions"><img src="https://img.shields.io/npm/l/vue-test-actions.svg?style=flat" alt="License"></a>
5+
<a href="https://biigpongsatorn.github.io/#/vue-test-actions"><img src="https://travis-ci.org/biigpongsatorn/biigpongsatorn.github.io.svg?branch=dev" alt="build status"></a>
6+
</p>
27

3-
βœ… Unit testing Vuex actions with Jest mocks. (🚧 WIP)
8+
# βœ… Vue Test Actions
49

5-
# Ref.
10+
Unit testing Vuex actions with Jest mocks.
611

7-
- [vuex-jest-mocking-examples](https://github.com/lmiller1990/vuex-jest-mocking-examples)
8-
- [vue-test-utils](https://github.com/vuejs/vue-test-utils)
9-
- [vuex.vuejs.org/guide/testing](https://vuex.vuejs.org/guide/testing.html)
10-
- [forum.vuejs](https://forum.vuejs.org/t/how-to-test-a-vuex-store-action-with-rootsate/22931)
11-
- [vue-test-utils](https://github.com/vuejs/vue-test-utils)
12+
# πŸ’» Install
13+
14+
```sh
15+
npm i --save vue-test-actions
16+
```
17+
or
18+
```sh
19+
yarn add vue-test-actions
20+
```
21+
22+
# πŸ•Ή Usage
23+
24+
```javascript
25+
import testAction from 'vue-test-actions'
26+
27+
testAction(action, payload, expectedCommits, expectedDispatchs, store)
28+
```
29+
30+
# βš™οΈ Params
31+
| Params | Type | Description |
32+
| ----------------- |:--------------| ----------------------------------|
33+
| action | Function | Action function |
34+
| payload | Any | Parameter send to action function |
35+
| expected commits | Array | Array of commit expectation |
36+
| expected dispatchs| Array | Array of dispatchs expectation |
37+
| store | Object | Object for mock store data such as `state` or `getter` |
38+
39+
40+
# πŸ”Ž Example
41+
42+
```javascript
43+
// user/actions.js
44+
45+
import userSerive from '../myUserService'
46+
47+
export async function getUser ({ commit, dispatch }, userId) {
48+
commit('setLoading', true)
49+
try {
50+
const { data } = await userSerive.fetchUser(userId)
51+
commit('setUser', data)
52+
dispatch('getUserPermission', data.id)
53+
} catch (e) {
54+
commit('setNotificationError', true)
55+
}
56+
commit('setLoading', false)
57+
}
58+
```
59+
60+
```javascript
61+
// user.spec.js
62+
63+
import testAction from 'vue-test-actions'
64+
import * as actions from '~/store/user/actions'
65+
import userSerive from '~/services/myUserService'
66+
67+
describe('getUser', () => {
68+
test('If success', () => {
69+
const payload = 1
70+
userSerive.fetchUser = jest.fn().mockReturnValue({ data: { id: 1 } })
71+
const expectedCommits = [
72+
{ type: 'setLoading', payload: true },
73+
{ type: 'setUser', payload: { id: 1 } },
74+
{ type: 'setLoading', payload: false }
75+
]
76+
const expectedDispatchs = [
77+
{ type: 'getUserPermission', payload: 1 }
78+
]
79+
testAction(actions.getUser, payload, expectedCommits, expectedDispatchs)
80+
})
81+
})
82+
83+
```
84+
85+
# 🀝 Contributing
86+
1. Fork this repository.
87+
2. Create new branch with feature name.
88+
3. Run `npm install` and `npm run dev`.
89+
4. Create your feature.
90+
5. Commit and set commit message with feature name.
91+
6. Push your code to your fork repository.
92+
7. Create pull request. πŸ™‚
93+
94+
# ⭐️ Support
95+
96+
```
97+
If you like this project, You can support me with starring ⭐ this repository.
98+
```
99+
100+
# πŸ–Š License
101+
102+
[MIT](LICENSE)
103+
104+
Developed with ❀️ and β˜•οΈ

0 commit comments

Comments
Β (0)