Vue Test Utils - Skip created hook
已经有一个问题,该解决方案有效。但是,它跳过了我所有测试套件中创建的钩子。我的代码看起来像这样。
describe('test suites', () => {
describe('test suite 1', () => {
test that should not ignore created hook
})
describe('test suite 2', () => {
Vue.mixin({
created() {
console.log("created() in global mixin")
}
});
const mergeCreatedStrategy = Vue.config.optionMergeStrategies.created;
Vue.config.optionMergeStrategies.created = (parent, child) => {
return mergeCreatedStrategy(parent);
};
// This makes it ignore the created hook in test suite 1 as well. I tried to put it in a const
// like this as well:
const options = {
install(Vue) {
Vue.mixin({
created() {
}
});
const mergeCreatedStrategy = Vue.config.optionMergeStrategies.created;
Vue.config.optionMergeStrategies.created = (parent, child) => {
return mergeCreatedStrategy(parent);
};
}
};
const ignoreCreate = createLocalVue();
ignoreCreate.use(options);
// and then pass it in the mount options, but still same behaviour for test suite 1.
})
})
即使使用localVue似乎也不起作用。我试图这样解决。
let localVue = createLocalVue();
localVue.mixin({
created(){}
})
const mergeCreatedStrategy = localVue.config.optionMergeStrategies.created;
localVue.config.optionMergeStrategies.created = (parent, child) => {
return mergeCreatedStrategy(parent);
};
但是即使没有将本地Vue应用于安装选项,它仍然会忽略为两个套件创建的钩子。
即使在测试套件之外声明了localVue,即使不应用localVue,也会忽略所有已创建的钩子。