Unit testing Mocha Chai vue测试vue组件:此.$notify不是功能
我正在使用这个组件: 从那以后,我所有的摩卡柴测试单元都失败了Unit testing Mocha Chai vue测试vue组件:此.$notify不是功能,unit-testing,vuejs2,mocha.js,Unit Testing,Vuejs2,Mocha.js,我正在使用这个组件: 从那以后,我所有的摩卡柴测试单元都失败了 this.$notify is not a function 这是我的登录规范: // Importing The testing library import { expect } from "chai"; import { mount } from '@vue/test-utils' // Importing The component I need to test import Login from "@/compon
this.$notify is not a function
这是我的登录规范:
// Importing The testing library
import { expect } from "chai";
import { mount } from '@vue/test-utils'
// Importing The component I need to test
import Login from "@/components/Login.vue";
// Mounting the component as in real life
const wrapper = mount(Login);
describe("Login test", () => {
it("getAuth() to be a function", () => {
expect(wrapper.vm.getAuth).to.be.a("function");
});
});
我试过mount、shallowMount和render,但运气不好
有解决办法吗
我在main.js中调用vue通知,如下所示:
import Notifications from "vue-notification";
Vue.use(Notifications);
谢谢大家!
编辑:
我试图补充
const $notify = require('vue-notification')
到我的Login.vue组件没有运气
编辑2:尝试像这样调用函数,但运气不佳:
this.$root.$notify({
group: 'foo',
title: 'Hello ',
text: 'Cool'
});
[Vue warn]: Error in mounted hook: "TypeError: this.$root.$notify is not a function"
*编辑:****由我决定********* 我把vue导入得很糟糕。请查看我的工作login.spec.js测试文件:
// THE ASSERTION LIBRARY
import { expect } from "chai";
// THE TESTING LIBRARY
import { mount } from "@vue/test-utils";
// THE COMPONENT THAT I WANT TO TEST
import Login from "@/components/Login.vue";
// THE EXTERNAL COMPONENTS LINKED TO MY LOGIN COMPONENT THAT I NEED TO JOIN
import Vue from 'vue';
import Vuelidate from 'vuelidate'
Vue.use(Vuelidate)
import {
required,
minLength,
between
} from "vuelidate/lib/validators";
import Notifications from "vue-notification";
import velocity from 'velocity-animate'
Vue.use(Notifications, { velocity });
// THE WRAPPER CONTAIN MY LOGIN MOUNTED COMPONENT, JUST LIKE IN THE REAL LIFE
const wrapper = mount(Login)
describe("Login test", () => {
it("getAuth() to be a function", () => {
expect(wrapper.vm.getAuth).to.be.a("function");
});
});