4
<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.

1 Answer 1

3
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();
    });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.