And*_*ena 68
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);
Run Code Online (Sandbox Code Playgroud)
如果你想使用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);
Run Code Online (Sandbox Code Playgroud)
var expect = chai.expect;
expect(foo).to.not.equal(null);
// or
expect(foo).to.not.be.null;
Run Code Online (Sandbox Code Playgroud)