nuxt-ava-e2e-unit-testing icon indicating copy to clipboard operation
nuxt-ava-e2e-unit-testing copied to clipboard

[docs] Add examples

Open vinayakkulkarni opened this issue 6 years ago • 7 comments

  • [x] Vuex (refer #15)
  • [ ] Vue-Router -> NLink, NChild examples.
  • [ ] Globals -> Nuxt modules $recaptcha, $auth etc.

vinayakkulkarni avatar May 14 '19 12:05 vinayakkulkarni

@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 avatar May 22 '19 19:05 waghcwb

@waghcwb : I really appreciate the help. Looking forward to it :)

vinayakkulkarni avatar May 22 '19 20:05 vinayakkulkarni

@waghcwb

I saw PR. Can I test vuex based on existing vuex without creating vuex?

jskim82 avatar Jun 07 '19 00:06 jskim82

@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.

waghcwb avatar Jun 11 '19 12:06 waghcwb

@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);
});

waghcwb avatar Jun 11 '19 16:06 waghcwb

@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 avatar Jun 11 '19 17:06 waghcwb

@waghcwb

Thank you~ Let's apply the test in my project. I will try the complicated vuex test ^. ^

jskim82 avatar Jun 11 '19 23:06 jskim82