1.0.6 • Published 5 years ago

@onedaycat/vue-test-actions v1.0.6

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

npm (scoped) GitHub Coverage Status Build Status

vue-test-actions

A utility to unit test Vuex actions

Install

npm install @onedaycat/vue-test-actions

or

yarn add @onedaycat/vue-test-actions

Usage

import testAction from '@onedaycat/vue-test-actions'

const value = await testAction(ACTION, EXPECTED_MUTATIONS, EXPECTED_DISPATCHS, ACTION_PAYLOAD, STORE)

Example

types.ts

export enum Mutations {
  FETCH_PRODUCT_BEGIN = 'fetchProductBegin',
  FETCH_PRODUCT_SUCCESS = 'fetchProductSuccess',
  FETCH_PRODUCT_FAILURE = 'fetchProductFailure',
}

actions.ts

import { ActionTree } from 'vuex'
import { Mutations } from './types'

const actions: ActionTree<Store.Product, Store.Root> = {
  async fetchProduct(context, payload: number) {
    context.commit(Mutations.FETCH_PRODUCT_BEGIN)
    try {
      context.commit(Mutations.FETCH_PRODUCT_SUCCESS, payload)
    } catch (e) {
      context.commit(Mutations.FETCH_PRODUCT_FAILURE, e)
    }
  },
}

export default actions

actions.test.ts

import { Mutations } from './types'
import testAction from '@onedaycat/vue-test-actions'
import actions from './actions'

it('should fetch product success', async () => {
  const actionPayload = 1
  const expectedMutations = [{
    type: Mutations.FETCH_PRODUCT_BEGIN,
  }, {
    type: Mutations.FETCH_PRODUCT_SUCCESS,
    payload: actionPayload,
  }]

  const expectedDispatchs = []

  await testAction(actions.fetchProduct, expectedMutations, expectedDispatchs, actionPayload)
})

Contributing

  1. Fork this repository.
  2. Create new branch with feature name in format feature/FEATURE_NAME
  3. Run npm install or yarn
  4. Create your feature.
  5. Commit and set commit message with feature name.
  6. Push your code to your fork repository.
  7. Create pull request.

Licence

MIT

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago