如何解决测试用例 vue test utils 中的工具提示警告?

Vis*_*gar 2 unit-testing vue.js jestjs vue-test-utils bootstrap-vue

使用 bootstrap-vue 的 vb-tooltip.hover 时,单元测试不断发出警告:
[BootstrapVue warn]: tooltip - 提供的目标不是有效的 HTML 元素。

Vis*_*gar 6

我通过在定义 componentData 时使用AttachTo: createContainer()找到了解决方案。每当重新定义包装器时也必须重新定义。

const createContainer = (tag = "div") => {
  const container = document.createElement(tag);
  document.body.appendChild(container);

  return container;
};

const componentData = {
  attachTo: createContainer(),
  store,
  localVue
};

const wrapper = shallowMount(Index, componentData);
Run Code Online (Sandbox Code Playgroud)