Added support for NaN. Tests included.

This commit is contained in:
Brad Cypert 2015-07-16 10:18:54 -07:00
parent 95a172bd5e
commit a5687a2648
5 changed files with 95 additions and 0 deletions

View file

@ -331,6 +331,25 @@ module.exports = function (chai, _) {
);
});
/**
* ### .NaN
* Asserts that the target is `NaN`.
*
* expect('foo').to.be.NaN;
* expect(4).not.to.be.NaN;
*
* @name NaN
* @api public
*/
Assertion.addProperty('NaN', function () {
this.assert(
isNaN(flag(this, 'object'))
, 'expected #{this} to be NaN'
, 'expected #{this} not to be NaN'
);
});
/**
* ### .exist
*

View file

@ -330,6 +330,37 @@ module.exports = function (chai, util) {
new Assertion(val, msg).to.not.equal(null);
};
/**
* ### .isNaN
* Asserts that value is NaN
*
* assert.isNaN('foo', 'foo is NaN');
*
* @name isNaN
* @param {Mixed} value
* @param {String} message
* @api public
*/
assert.isNaN = function (val, msg) {
new Assertion(val, msg).to.be.NaN;
};
/**
* ### .isNotNaN
* Asserts that value is not NaN
*
* assert.isNotNaN(4, '4 is not NaN');
*
* @name isNotNaN
* @param {Mixed} value
* @param {String} message
* @api public
*/
assert.isNotNaN = function (val, msg) {
new Assertion(val, msg).not.to.be.NaN;
};
/**
* ### .isUndefined(value, [message])
*

View file

@ -281,6 +281,22 @@ describe('assert', function () {
}, "expected null to not equal null");
});
it('isNaN', function() {
assert.isNaN('hello');
err(function (){
assert.isNaN(4);
}, "expected 4 to be NaN");
});
it('isNotNaN', function() {
assert.isNotNaN(4);
err(function (){
assert.isNotNaN('hello');
}, "expected 'hello' not to be NaN");
});
it('isUndefined', function() {
assert.isUndefined(undefined);

View file

@ -399,6 +399,26 @@ describe('expect', function () {
}, "expected { foo: \'bar\' } to be empty");
});
it('NaN', function() {
expect(NaN).to.be.NaN;
expect('foo').to.be.NaN;
expect({}).to.be.NaN;
expect(4).not.to.be.NaN;
expect([]).not.to.be.NaN;
err(function(){
expect(4).to.be.NaN;
}, "expected 4 to be NaN");
err(function(){
expect([]).to.be.NaN;
}, "expected [] to be NaN");
err(function(){
expect('foo').not.to.be.NaN;
}, "expected 'foo' not to be NaN");
});
it('property(name)', function(){
expect('test').to.have.property('length');
expect(4).to.not.have.property('length');

View file

@ -101,6 +101,15 @@ describe('should', function() {
}, "expected '' to be null")
});
it('NaN', function(){
'foo'.should.be.NaN;
(4).should.not.be.NaN;
err(function(){
(4).should.be.NaN;
}, "expected 4 to be NaN")
});
it('undefined', function(){
(0).should.not.be.undefined;