柴应该是未定义的 [英] Chai should is undefined

查看:56
本文介绍了柴应该是未定义的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了Mocha和Chai.

I have installed Mocha as well as Chai.

在我的单元测试中:

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可以正常工作,但是should未定义.

expect works as expected, but should is undefined.

为什么?

推荐答案

您应该在文件的开头调用 chai.should() 以使用should样式.

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

它将使用should属性扩展每个对象,以启动您的断言链.

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

您可以在 chai文档中找到更多用法示例.

这篇关于柴应该是未定义的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆