简体   繁体   English

如何测试 Quasar(作为 Vue CLI 插件)?

[英]How to test Quasar (as Vue CLI plugin)?

I have Vue project and I use Quasar Framework here.我有 Vue 项目,我在这里使用Quasar Framework The last one I use as Vue CLI Plugin and it works perfect ( code repo and live url ).我用作Vue CLI 插件的最后一个,它运行良好(代码仓库和实时 url )。

Now I want to add some unit tests to my project (using jest) and I encountered a problem I did not understand..现在我想在我的项目中添加一些单元测试(使用 jest),我遇到了一个我不明白的问题..

I try to write a simple test for NetworkWatcher component.我尝试为NetworkWatcher组件编写一个简单的测试。 This component uses QIcon component and I have to import it in my test:该组件使用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", () => {});

In this case I have an error:在这种情况下,我有一个错误:

在此处输入图像描述

After some experiments and searching I tried next经过一些实验和搜索,我接下来尝试了

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

And it works, I can go this way.. but I don't like it.它有效,我可以通过这种方式 go .. 但我不喜欢它。 It seems to be wrong?好像错了? So why the first way doesn't work?那么为什么第一种方法行不通呢?

I know what Quasar has a good documentation for "Quasar CLI" version and even has it's own test runner.我知道 Quasar 有一个很好的“Quasar CLI”版本文档,甚至有它自己的测试运行器。 But I want to use "Vue CLI plugin" version.但我想使用“Vue CLI 插件”版本。

Try using the code below, as it's not able to resolve the quasar dependency properly.尝试使用下面的代码,因为它无法正确解决类星体依赖关系。

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", () => {});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM