Vue Test Utils-跳过为特定测试套件创建的挂钩

时间:2019-09-18 07:39:13

标签: vue.js vue-test-utils

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,也会忽略所有已创建的钩子。

0 个答案:

没有答案