Vue.js Vue测试工具-跳过创建的挂钩
我想跳过在Vue.js Vue测试工具-跳过创建的挂钩,vue.js,jestjs,vue-test-utils,Vue.js,Jestjs,Vue Test Utils,我想跳过在created()hook中调用的所有方法。有办法做到这一点吗 所以不是这个 created() { this.getAllocations(); this.getModels(); this.getTeams(); this.getCustodians(); this.getDefaultFeeStructure(); } 我想要这
created()
hook中调用的所有方法。有办法做到这一点吗
所以不是这个
created() {
this.getAllocations();
this.getModels();
this.getTeams();
this.getCustodians();
this.getDefaultFeeStructure();
}
我想要这个
created() { }
值得注意的是,我实际上无法更改组件本身,但出于测试目的,这需要完成。您可以通过全局混合来完成(请参阅) 但是,对于您的情况,您需要一个自定义合并策略来防止组件上创建的钩子运行: 具有相同名称的钩子函数合并到一个数组中,以便调用所有这些函数。Mixin钩子将在组件自己的钩子之前被调用。() 请参阅上的工作示例
Vue.mixin({
创建(){
log(“在全局mixin中创建()”)
}
});
const mergeCreatedStrategy=Vue.config.optionMergeStrategies.created;
Vue.config.optionMergestracties.created=(父级、子级)=>{
返回合并策略(父级);
};
新Vue({
el:#vue应用程序“,
模板:“请参阅控制台输出以获取日志记录。在{{renderDate}}”,
数据(){
返回{
renderDate:新日期()
}
},
创建(){
log(“在组件中创建()”)
}
})
Vue.mixin({
created() {
console.log("created() in global mixin")
}
});
const mergeCreatedStrategy = Vue.config.optionMergeStrategies.created;
Vue.config.optionMergeStrategies.created = (parent, child) => {
return mergeCreatedStrategy(parent);
};
new Vue ({
el: "#vue-app",
template: '<p>See console output for logging. Rendered at {{renderDate}}</p>',
data() {
return {
renderDate: new Date()
}
},
created() {
console.log("created() in component")
}
})