Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
281 views
in Technique[技术] by (71.8m points)

javascript - 如何测试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..

(现在,我想在项目中添加一些单元测试(使用笑话),但遇到了一个我不明白的问题。)

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.

(而且行得通,我可以这样走..但是我不喜欢它。)

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插件”版本。)

  ask by zvadym translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try using the bellow code.

(尝试使用下面的代码。)

As it's not able to resolve the quasar dependancy 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", () => {});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...