Skip to content

Incognitus-Io/vuex-test-utils

Repository files navigation

Vuex-Test-Utils

Coverage Status
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

  1. install using yarn add -D @incognitus/vuex-test-utils
  2. 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..})