【发布时间】:2021-09-13 13:11:22
【问题描述】:
我有一个简单的变异方法,可以将元素添加到我的集合中。现在我正在尝试测试该方法,并开玩笑抛出如下所述的错误。
//Vuex
const state = {
customerComplaints : new Set()
};
// Mutation method
setCustomerComplaints(state, data) {
state.customerComplaints.add(data);
}
//Error I am getting when running the test
//TypeError: state.customerComplaints.add is not a function
//Jest test
it('should do something', () => {
const state = {
customerComplaints: {}
};
myStore.mutations.setCustomerComplaints(state, 'UI issue');
expect(state.customerComplaints).toBe('UI issue');
});
我试图模拟它,但我无法成功。请帮助我通过这个测试。
【问题讨论】: