我有一个Vue项目,我在这里使用了Quasar Framework。我使用的最后一个作为Vue CLI Plugin,它工作得很好(code repo和live url)。
现在我想向我的项目中添加一些单元测试(使用jest),但我遇到了一个我不理解的问题。
我尝试为NetworkWatcher组件编写一个简单的测试。这个组件使用QIcon组件,我必须在测试中导入它:
import { Quasar, QIcon } from "quasar";
import NetworkWatcher from "@/components/NetworkWatcher.vue";
const localVue = createLocalVue();
localVue.use(Vuex);
localVue.use(Quasar, { components: { QIcon } });
describe("NetworkWatcher.vue", () => {});在这种情况下,我有一个错误:

经过一些实验和搜索后,我尝试了下一步
import * as AllQuasar from "quasar";
const { Quasar } = AllQuasar;
const components = Object.keys(AllQuasar).reduce((object, key) => {
const val = AllQuasar[key];
if (val && val.component && val.component.name != null) {
object[key] = val;
}
return object;
}, {});
const localVue = createLocalVue();
localVue.use(Vuex);
localVue.use(Quasar, { components });它起作用了,我可以这样做..但我不喜欢这样。这似乎是错的!那么为什么第一种方法行不通呢?
我知道Quasar有一个很好的"Quasar CLI“版本的文档,甚至有它自己的测试运行程序。但我想使用"Vue CLI插件“版本。
发布于 2019-12-01 19:40:49
尝试使用下面的代码,因为它无法正确解析类星体依赖。
import { Quasar, QIcon } from "quasar-framework/dist/quasar.mat.esm"; //this line is modified
import NetworkWatcher from "@/components/NetworkWatcher.vue";
const localVue = createLocalVue();
localVue.use(Vuex);
localVue.use(Quasar, { components: { QIcon } });
describe("NetworkWatcher.vue", () => {});https://stackoverflow.com/questions/58974057
复制相似问题