<script lang="ts">
import {Component, Vue} from 'vue-property-decorator';
import {Action, Getter, namespace} from 'vuex-class';
import {User} from '@/types/userTypes';
const userModule = namespace('user');
@Component({
name: 'Header'
})
export default class Header extends Vue {
data: any;
@userModule.Getter user!: User;
}
</script>
The code above is a simple Header component that uses a Getter/namespace for displaying user data.
Question is how to mock the namespace('user', Getter)
Running the test I get:
[Vue warn]: Error in render: "TypeError: Cannot read property '_modulesNamespaceMap' of undefined"
If you have a sample of how to mock this, please share.
import {createLocalVue, shallowMount} from '@vue/test-utils';
import Vuex from 'vuex';
import Header from '@/components/Header.vue';
const localVue = createLocalVue();
localVue.use(Vuex);
const getters = {
user: jest.fn()
};
const store = new Vuex.Store({
modules: {
user: {
namespaced: true,
getters
}
}
});
describe('Header.vue', () => {
it('Instantiate component', () => {
const wrapper = shallowMount(Header, {
store,
localVue
});
expect(wrapper.isVueInstance()).toBeTruthy();
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With