I am attempting to write a test using vuex test utils. I have setup the test as such:
myModule.ts
export const mutations = {
[TYPES.SET_VALUE1](state: myModuleState, payload: TYPE1) {
//...
},
[TYPES.SET_VALUE2](state: myModuleState: payload: TYPE2) {
//...
},
[TYPES.SET_VALUE3](state: myModuleState, payload: TYPE3) {
//...
},
[TYPES.SET_VALUE4](state: myModuleState, payload: TYPE4) {
//...
}
};
myModule.spec.ts
import chai from 'chai';
import { expect } from 'chai';
import { mutations, myModule } from '@/store/modules/myModule';
import TYPES from '@/store/mutation-types';
const testValue:TYPE1 = {
name: 123
};
describe('mutations', () => {
it('TYPE1', () => {
// mock state
const state = {};
// apply mutation
mutations[TYPES.SET_VALUE1](state, testValue);
// assert result
expect(state).to.deep.equal(testValue);
});
});
and when I run I am getting the following error:
TS2345: Argument of type 'TYPE1' is not assignable to parameter of type 'TYPE1 & TYPE2 & TYPE3 & TYPE4'.
Type 'TYPE1' is not assignable to type 'TYPE2'.
It seems as though it expects the type of the argument to be all of the types at the same time? When I change the type of the argument, say from TYPE1 to TYPE2, the error changes to Type 'TYPE2' is not assignable to type 'TYPE1'
. What am I doing wrong?
Edit: I changed myModule.spec.ts to myModule.spec.js and removed the typed def on testValue. and the test passes just fine.