我正在迁移到Vue3,所以请原谅我不只是使用Pinia.我有一个这样的减速器:
export const mutations: MutationTree<UiState> = {
SET_LOADING: (state, loading) => {
Object.assign(state, loading); // before Vue3 this was Vue.set(...) for reactivity
},
};
像这样的测试
it('should set consultationLoading', () => {
const state = uiState();
const loading = true;
const { SET_LOADING } = mutations;
SET_LOADING(state, loading);
expect(state.loading).toBe(loading);
});
由于我不能再使用Vue.set()(从import Vue from 'vue';
开始),我只是按照另一篇文章中的建议使用Object.assign.但是状态在测试中没有更新.