wdetac
wdetac

Reputation: 2832

chai: Cannot read property 'not' of undefined

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

Upvotes: 0

Views: 1586

Answers (1)

Louis
Louis

Reputation: 151380

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.)

Upvotes: 2

Related Questions