chai: Cannot read property 'not' of undefined

最后都变了- 提交于 2019-12-02 18:55:10

问题


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

I run mocha test.js

The result is:

TypeError: Cannot read property 'not' of undefined

What is wrong with me? It seems .does return undefined. I remove .does and it works correctly. What is the correct usage?

The following code works.

expect([1, 2]).to.be.an('array').that.not.include(3);

回答1:


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.

If you check the releases information, you'll find for version 4.0.0, this:

Add does and but as new no-op assertion. (Related Issues: #700, #339 PRs: #621, #701)

(You can find the same information in the Github release, with the added benefit that the issue numbers are links to the actual issues.)



来源:https://stackoverflow.com/questions/44369369/chai-cannot-read-property-not-of-undefined

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!