i try to use the testing tool mocha in node. Consider the following test scenario
var requirejs = require(\'requirejs\');
requirejs.config({
//Pass the top-
That's a known problem with the should
library: As it extends object
, of course it only works when you have a concrete object. As null
, by definition, means that you don't have an object, you can not call any methods on it or access any of its properties.
Hence, should
is not available in this case.
Basically, you have two options of how to deal with this:
actual
and expected
. This way, as long as you do not expect null
, you have an object in the beginning and hence can access its should
property. But, this is not nice, as it changes semantics, and does not work in all cases.should
library by another assertion library that does not have this problem.Personally, I'd go with option 2, and my highly subjective personal favorite for this is node-assertthat (which has been written by me, hence it's my favorite).
Anyway, there are lots of other options, such as expect. Feel free to use any of these assertion libraries that best suits your style of writing tests.
One more option that I don't see mentioned here:
should(err === null).be.null
In you example that would would be:
should(accountExists).be.null
I always find expect
works better with null
and undefined
as follows:
expect(err).be.null
You can use should directly
should.not.exist(err);
I had the same problem. I solved it by using:
(err === null).should.be.true;