How to use unit test with vuex-loading
See original GitHub issueI 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: `
<template>
<div class="multipane__aside">
<v-btn
:disabled="$loading.isLoading('call ajax')"
@click="fetchResults"
color="primary"
>
<v-loading loader='call ajax'>
<template slot='spinner'>Loading...</template>
</v-loading>
Call ajax
</v-btn>
<div v-if="$loading.isLoading('call ajax')">call ajax...</div>
-
{{ item.title }}
{{ item.body }}
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
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Testing | Vuex
The main parts we want to unit test in Vuex are mutations and actions. ... we can use webpack and inject-loader to bundle...
Read more >How to unit test a Vuex store - Dev tips and tricks
Tutorial on how two different approaches to unit testing a Vuex store. ... Mutations take a state object and an optional payload object....
Read more >Unit testing Vuex modules with Jest - LogRocket Blog
In this article, I'll guide you through implementing a Vuex module in TypeScript, then unit testing it using Jest. The complete code for ......
Read more >Guide to Unit Testing Vue Components - TestDriven.io
Use mocks to test asynchronous functions; Check the code coverage of your unit tests; Structure your unit test files. If you're interested in ......
Read more >Structuring and testing a Vue/Vuex app with vue-test-utils
TodoContainer — Failing Test · We import vue , vuex , and do Vue.use(Vuex . · Before each test, we mock what the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hi @gabrielrobert, would you help to add a “testing” part into README.md file according to your testing experiences and problems? I need to improve vue-wait to make it more testable. It would be awesome for the people asking for tests (including me) 😃
In some cases, we cannot mock
v-wait. This library is widely used in our project and stubs/mocks prevent proper testability. For instance:Component:
Test:
It is not possible to test proper
ulrendering withoutv-waitcomponent. You should: