Chai should is undefined

試著忘記壹切 提交于 2019-12-02 04:43:15

问题


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.



来源:https://stackoverflow.com/questions/42094419/chai-should-is-undefined

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