nuxt-ava-e2e-unit-testing
nuxt-ava-e2e-unit-testing copied to clipboard
[docs] Add examples
- [x] Vuex (refer #15)
- [ ] Vue-Router -> NLink, NChild examples.
- [ ] Globals -> Nuxt modules $recaptcha, $auth etc.
@vinayakkulkarni,
I've opened a PR with a simple example of how to test Vuex, it still need some work, I'll be adding some updates during the week (little busy at work..)
#15
@waghcwb : I really appreciate the help. Looking forward to it :)
@waghcwb
I saw PR. Can I test vuex based on existing vuex without creating vuex?
@jskim82,
Sorry, I think I did not understand your question. We create the Vuex instance to mock the results for the tests.
But I'm not fully experienced with Jest tests, maybe there's another way to do it.
@jskim82,
I think I gotcha. You can import your state, mutations, etc from the store and use as well.
import { state as mockState, mutations as mockMutations } from '@/store';
const localVue = createLocalVue();
localVue.use(Vuex);
function createStore({ state, mutations, actions }) {
return new Vuex.Store({
state,
mutations,
actions,
});
}
let store = createStore({ state, mutations, actions });
test('component should mount', t => {
const wrapper = shallowMount(YourComponent, { localVue, store });
t.is(wrapper.isVueInstance(), true);
});
@jskim82, I've added a example of testing using the actual state from the store. Check #15
@vinayakkulkarni, I've finished adding examples for testing a vuex store, can you validate please?
@waghcwb
Thank you~ Let's apply the test in my project. I will try the complicated vuex test ^. ^