menu

Testing Library

Simple and complete DOM testing utilities that encourage good testing practices.

Channels
Chat
view-forward
# All channels
view-forward
# General
view-forward
# General Help
view-forward
# Angular Help
view-forward
# Cypress Help
view-forward
# DOM Help
view-forward
# React Help
view-forward
# TestCafe Help
view-forward
# Vue Help
view-forward
Team

Are there any reasons why it is not supported to use the whole vuex store…

September 27, 2019 at 2:24pm

Are there any reasons why it is not supported to use the whole vuex store during testing?

September 27, 2019 at 2:24pm (Edited 6 months ago)
I am surprised, that the default approach here is to add each Store Module separately during test setup. As I try to reduce implementation details, I see no benefit in importing the exact store modules which are used by the mounted component or any of its child components.
Just think about a working and well-tested feature. Now a child-child-child-component does some unrelated store interaction for another feature. Now my old test may fail, but its feature is still working. Only because of a missing store module.
I am trying to understand why the render function only accepts "The object definition of a Vuex store" instead of the store itself. Are there any reasons why this would be a bad idea?

September 28, 2019 at 10:22am
Hi Cristoph! In Vue Testing Library we accept a store object that it's used to initialize a Vuex instance (here). You can pass either a full store or a single module, depending on your store structure.
Just to make sure I fully understand your request: do you suggest that VTL should accept a { store: new Vuex.Store(whatever) } as a parameter, instead of { store: whatever }? If that's the case, would you mind opening up a new issue with the request and the motivation behind?
Thank you! :)
  • reply
  • like

September 29, 2019 at 9:29am
Hi and yes, I was thinking about accepting { store: new Vuex.Store(whatever) } as a parameter. But when I now think about it this might be a misconception on our side. We use the following code to initialise our store:
Vue.use(Vuex)
const store = new Vuex.Store()
store.registerModule('test', TestModule)
store.registerModule('auth', AuthenticationModule)
configureModerator(store)
export default store
Reading the docs again we should instead use something like that:
const store = new Vuex.Store({
modules: {
test: TestModule,
auth: AuthenticationModule
}
})
Which make it easy to use the same modules with VTL. Only the mediator pattern is left, which helps to interact between store modules: https://itnext.io/decouple-vuex-actions-with-the-mediator-pattern-58a8879de1b4 I do not like the idea of registering this in every test manually...
  • reply
  • like

October 1, 2019 at 8:15am
I see. Would you mind opening up a new issue with the request and the motivation behind? It looks like a legit use case.
  • reply
  • like