【发布时间】:2019-11-03 17:25:45
【问题描述】:
这是 MOCHA CHAI 单元测试:users.spec.js:
import { expect } from "chai";
import { shallowMount } from "@vue/test-utils";
import Users from "@/components/Users.vue";
const wrapper = shallowMount(Users);
describe("Users test", () => {
it("Displays nice hello message", () => {
expect(wrapper.vm.$data.msg).to.equal("Welcome to Crypto Info");
});
it("users model is an array", () => {
expect(wrapper.vm.$data.users).to.be.an("array");
});
it("getUsers() to be a function", () => {
expect(wrapper.vm.$methods.getUsers()).to.be.a("function");
});
});
我找不到第三个测试的正确语法。我已经尝试了很多东西。 $methods.getUsers() 不起作用。
1) Users test
getUsers() to be a function:
TypeError: Cannot read property 'getUsers' of undefined
at Context.it (dist\js\webpack:\tests\unit\users.spec.js:15:1)
你能帮帮我吗? 谢谢。
【问题讨论】:
-
测试方法是否存在似乎不是一个有用的测试。更有效的测试是验证方法调用的结果。
标签: vue.js webpack mocha.js chai