lundi 9 décembre 2019

How to unit test a typescript Vue Component that uses vuex-class

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

Aucun commentaire:

Enregistrer un commentaire