mrcrowl / vuex-typex

Typescript builder for strongly-typed access to Vuex Store modules
MIT License
193 stars 22 forks source link

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

Open nathan815 opened 4 years ago

nathan815 commented 4 years ago

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

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?

mrcrowl commented 4 years ago

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.