【发布时间】:2019-09-15 10:46:01
【问题描述】:
我有一个简单的测试:
describe('App', () => {
let store;
beforeEach(() => {
store = new Vuex.Store({
modules: {
auth: {
namespaced: true,
getters: {
isLoggedIn: () => true,
}
}
}
});
});
test('App hides navbar when user is logged in', () => {
const wrapper = shallowMount(App, { store, localVue });
expect(wrapper.contains(Nav)).toBe(false);
// store.getters['auth/isLoggedIn'] = () => false; // Not possible
});
});
但我无法更改 getter 值,并且在控制台中看到此错误:
TypeError: Cannot set property auth/isLoggedIn of # which has only a getter
如何在我的测试中设置 getter 值?
【问题讨论】:
标签: javascript vue.js jestjs vue-test-utils