In Vuex + Jest, how to unit test a getter which is calling the store? In Vuex + Jest, how to unit test a getter which is calling the store? vue.js vue.js

In Vuex + Jest, how to unit test a getter which is calling the store?


After much research, I realized I had to mock the store dependency with Jest. This seems the correct way to do it and pass the test:

import Search from '@/store/modules/search'jest.mock('@/store/index.js', () =>({  getters: {    queryToGet: 'barfoo'  }}))jest.mock('@/store/modules/search.js')describe('search.js', () => {  test('The adress getter gets the right adress', () => {    const state = {      baseAdress: 'http://foobar.com/'    }    expect(Search.getters.adressToGet(state))    .toBe('http://foobar.com/barfoo')  })})


matomo