首頁  >  問答  >  主體

解決Vue Test Utils中測試案例中的工具提示警告的方法

<p>在使用bootstrap-vue的v-b-tooltip.hover時,單元測試一直會出現警告:</p><p><strong>[BootstrapVue warn]: tooltip - 提供的目標不是有效的HTML元素。 </strong></p>
P粉293341969P粉293341969420 天前449

全部回覆(1)我來回復

  • P粉163465905

    P粉1634659052023-08-27 11:13:36

    我發現在定義componentData時使用attachTo: createContainer()可以解決問題。同時,每當wrapper被重新定義時,也必須重新定義。

    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);

    回覆
    0
  • 取消回覆