Chai should is undefined

2019-03-02 07:23发布

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条回答
霸刀☆藐视天下
2楼-- · 2019-03-02 07:59

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.

查看更多
登录 后发表回答