f / f/vue-wait

How to use unit test with vuex-loading

Open
#17 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
2k
Forks
98
PR merge metrics
No merged PRs in 30d

Description

I would like to write a unit test with the async action such as:
**File navigation.spec.js:**
`

import Vue from 'vue'

import Vuex from 'vuex'
import Vuetify from 'vuetify'
import vueLoading from 'vuex-loading'
import { shallow, createLocalVue } from '@vue/test-utils'
import Navigation from '@/components/Navigation'
import { stat } from 'fs';

Vue.use(Vuetify)
Vue.use(vueLoading)

const localVue = createLocalVue()
localVue.use(Vuex)

describe('Navigation', () => {
let store
let actions
let state

beforeEach(() => {
state = {
items: []
}

actions = {
getAsync: jest.fn()
}

store = new Vuex.Store({
state,
actions
})
})

it('dispatches an getAsync action', () => {
const wrapper = shallow(Navigation, {
store,
localVue
})
wrapper.find('button').trigger('click')
expect(actions.getAsync).toHaveBeenCalled()
})
})

`

**File Navigation.vue:**
`





Loading...

Call ajax

call ajax...



  • {{ item.title }}

    {{ item.body }}


import { mapState, mapActions } from 'vuex'
export default {
name: 'RecipeNavigation',
computed: {
...mapState(['items'])
},
methods: {
...mapActions(['getAsync']),
fetchResults () {
this.getAsync()
},
onClose () {
this.$emit('close', this.$el)
}
}
}

`

**The result of test:**
[Vue warn]: Error in config.errorHandler: "TypeError: Cannot read property 'isLoading' of undefined"

Please help me to pass this issue. Thank you for any help you can offer

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.