Jestjs Nuxt&x2B;笑话:未知自定义元素if";组件“;未设置
我喜欢Nuxt的一点是不必包含所有使用过的组件。但这不是开玩笑。 我从默认的nuxt应用程序开始使用jest。我在“Logo.Vue”中添加了如下自定义元素:Jestjs Nuxt&x2B;笑话:未知自定义元素if";组件“;未设置,jestjs,nuxt.js,Jestjs,Nuxt.js,我喜欢Nuxt的一点是不必包含所有使用过的组件。但这不是开玩笑。 我从默认的nuxt应用程序开始使用jest。我在“Logo.Vue”中添加了如下自定义元素: <template> <div class="VueToNuxtLogo"> <MyComponent /> </div> </template> 是否有任何方法可以使用诸如Nuxt do之类的Jest自动导入组件?因此目前无法这样做,我
<template>
<div class="VueToNuxtLogo">
<MyComponent />
</div>
</template>
是否有任何方法可以使用诸如Nuxt do之类的Jest自动导入组件?因此目前无法这样做,我在github上发现了这个问题: 但手动操作并不难,我在“tests/beforeAllTests.js”文件中添加了此函数:
import path from 'path';
import glob from 'glob';
import Vue from 'vue';
export default function beforeAllTests () {
// Automatically register all components
const fileComponents = glob.sync(path.join(__dirname, '../components/**/*.vue'));
for (const file of fileComponents) {
const name = file.match(/(\w*)\.vue$/)[1];
Vue.component(name, require(file).default);
}
}
在每次测试之前添加我调用它
import beforeAllTests from '~/tests/beforeAllTests';
describe('Some tests', () => {
beforeAll(async () => {
beforeAllTests();
});
import path from 'path';
import glob from 'glob';
import Vue from 'vue';
export default function beforeAllTests () {
// Automatically register all components
const fileComponents = glob.sync(path.join(__dirname, '../components/**/*.vue'));
for (const file of fileComponents) {
const name = file.match(/(\w*)\.vue$/)[1];
Vue.component(name, require(file).default);
}
}
import beforeAllTests from '~/tests/beforeAllTests';
describe('Some tests', () => {
beforeAll(async () => {
beforeAllTests();
});