Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js Vue测试工具-跳过创建的挂钩_Vue.js_Jestjs_Vue Test Utils - Fatal编程技术网

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")
  }
})