我正在尝试使用Jest
为我的React应用程序运行测试,但是我的测试因为require.context
不是函数的错误而继续失败。我正在寻找Jest
不会窒息的功能的替代品。我正在尝试动态require
并修改*.vue
中的某些Vue.js
文件,以便稍后在我的应用程序中使用。除此之外,我偶尔会收到无法识别.vue
文件格式的错误,并说它们无法解析。这是有问题的代码:
function inject(comp) {
comp.methods = Object.assign({}, comp.methods, stub.methods);
return comp;
}
let req = require.context('./', false, /\.vue$/);
components.forEach(function (component) {
try {
let filePath = __dirname + "\\" + component + '.vue';
let injected = inject(req(filePath));
Vue.component(getComponentName(component), injected);
let appComponent = {
name: injected.name,
props: {
autocompletion: {
metadata: getComponentName('template'),
score: xTemplatesScore,
attributes: injected.props || []
}
}
};
appComponents.push(appComponent);
} catch (err) {
console.log(err);
console.error('Vue file was not found for component:' + component + '. Please rename your files accordingly ( component-name.vue )');
}
});