Awesome
Vuex-Test-Utils
This is a collection of test utilities for vuex. For actions you can check if things are commited or dispatched, and what their payload was.
Getting started
- install using
yarn add -D @incognitus/vuex-test-utils
- configure
jest.config.js
module.export = {
setupFilesAfterEnv: ['@incognitus/vuex-test-utils'],
}
Basic useage
expect.action(actions.foobar).toCommitWithPayload('foo', 'bar')
or
expect.action(actions.fizzbuzz).toDispatchWithPayload('fizz', 'buzz')
when checking order
exect.action(actions.foofizz).toCommitInOrder('foobar', 'fizzbuzz')
Things that can be checked are:
- toCommit
- toCommitWithPayload
- toCommitAsRoot
- toCommitInOrder
- toDispatch
- toDispatchWithPayload
- toDispatchAsRoot
- toDispatchInOrder
Passing action payload and contexts
Payload, state, root state, getters, and root getters can also be passed in with the option parameters on the expect.action
method
// Payload
expect.action(actions.foobar, {foo: bar})
// Context
exect.action(actions.foobar, undefined, {state: {foo: 'bar'}, rootState: {version: '1.0.0'}, etc..})