Chai should is undefined

2019-03-02 07:33发布

问题:

I have installed Mocha as well as Chai.

In my unit test:

import {expect, should} from "chai";

describe("array", function () {
        it("has length of 1", function (done) {
            var arr = ["B"];
            expect(arr).have.lengthOf(1);
            arr.should.have.lengthOf(1);
        });
});

expect works as expected, but should is undefined.

Why?

回答1:

You should call chai.should() at the begin of the file to use should style.

It will extends each object with a should property to start your assertions chain.

You can find more usage examples in chai documentation.