在我的 ContactForm 组件中,我有 2 个计算的 mapGetters
computed: {
...mapGetters(["language"]),
...mapGetters("authentication", ["loading"]),
第一个在我的stoe/getters.js中定义
export const language = state => {
return state.language;
};
第二个定义在我的store/modules/authentication.js
const authentication = {
namespaced: true,
getters: {
user: state => {
return state.user
},
loading: state => {
return state.loading
}
},
我正在尝试模拟我的 Vuex 商店,第一个“语言”很容易,
export const storeMock = Object.freeze({
state: {},
actions: {},
getters: {
language: () => { . // <= FINE
return "en";
},
authentication: { . // <= . WRONG
loading: () => {
return false;
}
}
}
})
但是我应该如何模拟“身份验证”模块中的第二个“加载”?
最佳答案
如果您在应用程序中控制台记录商店,命名空间的 getter 有一个键 namespace/getterName
,所以我认为这应该有效
export const storeMock = Object.freeze({
state: {},
actions: {},
namespaced: true,
getters: {
language: () => { // <= FINE
return "en";
},
'authentication/loading' : () => {
return false;
}
}
})
关于Vue.js test-utils 如何模拟模块中的 getter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52613120/