问题描述
我是chai
和mocha
的新手,我在第一个测试用例中使用了示例代码.这是我的代码.
I am new to chai
and mocha
and I use the sample code for my first test case. Here is my code.
var chai = require("chai");
var mocha = require("mocha");
var expect = chai.expect;
describe("Test", function() {
it("Test", function() {
expect([1, 2]).to.be.an('array').that.does.not.include(3);
});
});
我运行mocha test.js
结果是:
TypeError: Cannot read property 'not' of undefined
我怎么了?看来.does
返回未定义.我删除了.does
,它可以正常工作.正确的用法是什么?
What is wrong with me? It seems .does
return undefined. I remove .does
and it works correctly. What is the correct usage?
以下代码有效.
expect([1, 2]).to.be.an('array').that.not.include(3);
推荐答案
如果我使用Chai 4运行您的代码,它就可以工作.当我将其降级为Chai 3时,您会收到错误消息. Chai 4.0.0中将does
添加为无操作断言.您使用的Chai版本早于4.0.0.
If I run your code with Chai 4, it works. When I downgrade it to Chai 3 I get the error you get. does
was added as a no-op assertion in Chai 4.0.0. You are using a version of Chai that predates 4.0.0.
如果您查看发布信息,则会发现版本4.0.0如下:
If you check the releases information, you'll find for version 4.0.0, this:
(您可以在Github中找到相同的信息发行版 ,还有一个好处,就是问题编号是指向实际问题的链接.)
(You can find the same information in the Github release, with the added benefit that the issue numbers are links to the actual issues.)
这篇关于柴:无法读取未定义的属性“不"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!