Mocha支持您想要的任何断言库.你可以看看它是如何处理断言的:http://mochajs.org/#assertions.我不知道你想用哪一个.
考虑到你正在使用Chai,这是非常流行的,这里有一些选项:
将"FoO"视为要测试的目标变量
var assert = chai.assert;
assert(foo) // will pass for any truthy value (!= null,!= undefined,!= '',!= 0)
// or
assert(foo != null)
// or
assert.notEqual(foo, null);
如果你想用assert
,你甚至不需要柴.就用它吧. node 本机支持:https://nodejs.org/api/assert.html#assert_assert
var should = require('chai').should();
should.exist(foo); // will pass for not null and not undefined
// or
should.not.equal(foo, null);
var expect = chai.expect;
expect(foo).to.not.equal(null);
// or
expect(foo).to.not.be.null;
PS:不相关,但Jest 的是,有一个toBeNull
函数.你可以做expect(foo).not.toBeNull();
或expect(foo).not.toBe(null);