【发布时间】:2021-03-07 09:23:42
【问题描述】:
我喜欢 Nuxt 的一件事是不必包含所有使用过的组件。但这不适用于 Jest。
我从默认的 nuxt 应用开始玩笑。我在“Logo.Vue”中添加了一个自定义元素,如下所示:
<template>
<div class="VueToNuxtLogo">
<MyComponent />
</div>
</template>
我添加了组件文件'MyComponent.vue':
<template>
<span>My great component<span>
</template>
当我运行应用程序时,我可以看到 MyComponent。
但“Logo.spec.js”测试返回此错误:[Vue warn]: Unknown custom element: <MyComponent> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
如果我包含这样的组件,测试就可以了。
import MyComponent from './MyComponent'
export default {
components: { MyComponent }
}
有没有办法像 Nuxt 那样使用 Jest 自动导入组件?
【问题讨论】: