I'm using the should.js framework (v8.2.x) to unit test and have been playing around with some very basic tests. However, I ran into this issue with the tests failing, which has stumped me.
I defined this dummy function to test, add
:
var add = function(a, b) {
if (isNaN(a) || isNaN(b)) {
throw new Error('One of the arguments is not a number');
}
return +a + +b
};
Now here're my dummy tests:
should.equal(add('1', '1'), '2'); // passes
add('1', '1').should.equal('2') // fails!
Now according to their github, should(something)
and something.should
usually return the same thing, but there's no additional info on the differences.
According to their API documentation, should.equal
is the same as assert.equal
. But this test passes for me:
assert.equal(add('1','1'), '2'); // passes
So I have three questions:
- Why does
add('1', '1').should.equal('2')
not pass? - Why are the two usages of should yielding different results?
- Why do the docs say
should.equals
is the same asassert.equals
when they actually have different behavior?