vuex-typex icon indicating copy to clipboard operation
vuex-typex copied to clipboard

Unit/integration testing with vuex-typex and vue-test-utils?

Open nathan815 opened this issue 5 years ago • 1 comments

Great little library - thanks for making this! 💯

I am now trying to figure out how to mock the store for testing. In vue-test-utils docs it talks about creating a store by instantiating a Vuex.Store and setting up a localVue instance. However, with vuex-typex we use StoreBuilder.vuexStore() instead to create a store and then call the modules' strongly typed functions rather than Vuex.Store methods.

My goal is to be able to

  • set initial state test data
  • pass to the store mock action/getter functions (jest.fn) for call verification
  • assert on parts of the state

Has anyone figured out how to do this with vuex-typex? I think I know how setting initial state and asserting state would work, but I am not sure how to pass in mock actions/getters for given module(s) to the store.


Also, what would be the "best" way to unit test the store's actions/getters/mutations themselves?

nathan815 avatar Dec 30 '19 21:12 nathan815

You can look at the tests folder for some examples of how I test the repo itself, which is not far from what you're trying to do.

To test the actions/getters/mutations independently, I've used jest + manual mocks (__mocks__/) with some success. You end up needing to separate the actions/getters/mutations into their own files, independent of the store.

mrcrowl avatar Jan 17 '20 21:01 mrcrowl