1.0.6 • Published 6 years ago

vue-test-actions v1.0.6

Weekly downloads
6
License
MIT
Repository
github
Last release
6 years ago

✅ Vue Test Actions

Unit testing Vuex actions with Jest mocks.

💻 Install

npm i --save vue-test-actions

or

yarn add vue-test-actions

🕹 Usage

import testAction from 'vue-test-actions'

testAction(action, expectedCommits, expectedDispatchs, payload, store)

⚙️ Params

ParamsTypeDefaultDescription
actionFunction-Action function
expected commitsArray[]Array of commit expectation
expected dispatchsArray[]Array of dispatchs expectation
payloadAnyundefinedParameter send to action function
storeObject{ state: {}, getter: {} }Object for mock store data such as state or getter

🔎 Example

// user/actions.js

import userSerive from '../myUserService'

export async function getUser ({ commit, dispatch }, userId) {
  commit('setLoading', true)
  try {
    const { data } = await userSerive.fetchUser(userId)
    commit('setUser', data)
    dispatch('getUserPermission', data.id)
  } catch (e) {
    commit('setNotificationError', true)
  }
  commit('setLoading', false)
}
// user.spec.js

import testAction from 'vue-test-actions'
import * as actions from '~/store/user/actions'
import userSerive from '~/services/myUserService'

describe('getUser', () => {
  test('If success', () => {
    const payload = 1
    userSerive.fetchUser = jest.fn().mockReturnValue({ data: { id: 1 } })
    const expectedCommits = [
      { type: 'setLoading', payload: true },
      { type: 'setUser', payload: { id: 1 } },
      { type: 'setLoading', payload: false }
    ]
    const expectedDispatchs = [
      { type: 'getUserPermission', payload: 1 }
    ]
    testAction(actions.getUser, expectedCommits, expectedDispatchs, payload)
  })
})

🤝 Contributing

  1. Fork this repository.
  2. Create new branch with feature name.
  3. Create your feature.
  4. Commit and set commit message with feature name.
  5. Push your code to your fork repository.
  6. Create pull request. 🙂

⭐️ Support

If you like this project, You can support me with starring ⭐ this repository.

🖊 License

MIT

Developed with ❤️ and ☕️

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago