mardi 28 avril 2020

TypeError with vue-testing-library and Vuex

I want to test a Vue application using the vue-testing-library. My application uses Vuex. I get a TypeError when trying to render the App component.

TS2322: Type 'StoreOptions<State>' is not assignable to type 'StoreOptions<{}>'.
Types of property 'getters' are incompatible.     
Type 'GetterTree<State, State> | undefined' is not assignable to type 'GetterTree<{}, {}> | undefined'.
Type 'GetterTree<State, State>' is not assignable to type 'GetterTree<{}, {}>'.         
Type '{}' is not assignable to type 'State'.

I render the App component this way.

const finder = render(App, {
    store: options,
    router,
    i18n,
});

Where options is:

const options: StoreOptions<State> = {
    state: {
        username: '',
        token: '',
        refresh: '',
    },
    mutations: {
        storeToken: function (state, token: string) {
            state.token = token;
        },
        storeRefresh: function (state, refresh: string) {
            state.refresh = refresh;
        },
        storeUsername: function (state, username: string) {
            state.username = username;
        },
        deleteTokens: function (state) {
            state.refresh = '';
            state.token = '';
        }
    },
    actions: {
        rescindRefreshToken: async function (context) {
            // ...
        },
        refreshAccessToken: async function (context) {
            // ...
        }
    },
    modules: {}
}

Aucun commentaire:

Enregistrer un commentaire