unexpected
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -272,2 +272,14 @@ // Copyright (c) 2013 Sune Simonsen <sune@we-knowhow.dk> | ||
expect.addAssertion('[not] to be null', function () { | ||
this.assert(this.obj === null); | ||
}); | ||
expect.addAssertion('[not] to be undefined', function () { | ||
this.assert(typeof this.obj === 'undefined'); | ||
}); | ||
expect.addAssertion('[not] to be NaN', function () { | ||
this.assert(isNaN(this.obj)); | ||
}); | ||
expect.addAssertion('[not] to be (a|an)', function (type) { | ||
@@ -371,2 +383,10 @@ var subject = this.obj; | ||
expect.addAssertion('[not] to be finite', function () { | ||
this.assert(typeof this.obj === 'number' && isFinite(this.obj)); | ||
}); | ||
expect.addAssertion('[not] to be infinite', function () { | ||
this.assert(typeof this.obj === 'number' && !isNaN(this.obj) && !isFinite(this.obj)); | ||
}); | ||
expect.addAssertion('[not] to be within', function (start, finish) { | ||
@@ -373,0 +393,0 @@ this.args = [start + '..' + finish]; |
{ | ||
"name": "unexpected", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"author": "Sune Sloth Simonsen <sune@we-knowhow.dk>", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -94,3 +94,4 @@ # Unexpected | ||
expect(1, 'to be', 1); | ||
expect(NaN, 'not to be', NaN); | ||
expect(undefined, 'to be undefined'); | ||
expect(null, 'to be null'); | ||
expect(1, 'not to be', true); | ||
@@ -136,2 +137,13 @@ expect('1', 'not to be', 1); | ||
**NaN**: asserts that the value is `NaN` | ||
```js | ||
expect(NaN, 'to be NaN'); | ||
expect({}, 'to be NaN'); | ||
expect(2, 'not to be NaN'); | ||
expect(null, 'not to be NaN'); | ||
expect(undefined, 'to be NaN'); | ||
expect("String", 'to be NaN'); | ||
``` | ||
**match**: asserts `String` regular expression match | ||
@@ -209,2 +221,11 @@ | ||
**finite/infinite**: asserts a finite or infinite number | ||
```js | ||
expect(123, 'to be finite'); | ||
expect(Infinity, 'not to be finite'); | ||
expect(Infinity, 'to be infinite'); | ||
expect(false, 'not to be infinite'); | ||
``` | ||
**within**: asserts a number within a range | ||
@@ -211,0 +232,0 @@ |
@@ -53,6 +53,9 @@ /*global describe, it, expect*/ | ||
expect(1, 'to be', 1); | ||
expect(NaN, 'not to be', NaN); | ||
expect(1, 'not to be', true); | ||
expect('1', 'not to be', 1); | ||
expect(null, 'not to be', undefined); | ||
expect(null, 'to be null'); | ||
expect(0, 'not to be null'); | ||
expect(undefined, 'not to be null'); | ||
expect(undefined, 'to be undefined'); | ||
if (typeof Buffer !== 'undefined') { | ||
@@ -377,2 +380,38 @@ var buffer = new Buffer([0x45, 0x59]); | ||
describe('finite assertion', function () { | ||
it('asserts a finite number', function () { | ||
expect(123, 'to be finite'); | ||
expect(0, 'to be finite'); | ||
expect(Infinity, 'not to be finite'); | ||
expect(-Infinity, 'not to be finite'); | ||
expect(NaN, 'not to be finite'); | ||
expect(null, 'not to be finite'); | ||
expect({}, 'not to be finite'); | ||
it('throws when the assertion fails', function () { | ||
expect(function () { | ||
expect(Infinity, 'to be finite'); | ||
}, 'to throw exception', 'expected Infinity to be finite'); | ||
}); | ||
}); | ||
}); | ||
describe('finite assertion', function () { | ||
it('asserts a infinite number', function () { | ||
expect(123, 'not to be infinite'); | ||
expect(0, 'not to be infinite'); | ||
expect(Infinity, 'to be infinite'); | ||
expect(-Infinity, 'to be infinite'); | ||
expect(NaN, 'not to be infinite'); | ||
expect(null, 'not to be infinite'); | ||
expect({}, 'not to be infinite'); | ||
it('throws when the assertion fails', function () { | ||
expect(function () { | ||
expect(123, 'to be finite'); | ||
}, 'to throw exception', 'expected 123 to be infinite'); | ||
}); | ||
}); | ||
}); | ||
describe('within assertion', function () { | ||
@@ -479,2 +518,23 @@ it('asserts a number within a range', function () { | ||
describe('to be NaN assertion', function () { | ||
it('assert that the value is NaN or not', function () { | ||
expect(NaN, 'to be NaN'); | ||
expect({}, 'to be NaN'); | ||
expect(2, 'not to be NaN'); | ||
expect(null, 'not to be NaN'); | ||
expect(undefined, 'to be NaN'); | ||
expect("String", 'to be NaN'); | ||
}); | ||
it('fails when the assertion fails', function () { | ||
expect(function () { | ||
expect(0, 'to be NaN'); | ||
}, 'to throw', "expected 0 to be NaN"); | ||
expect(function () { | ||
expect(NaN, 'not to be NaN'); | ||
}, 'to throw', "expected NaN not to be NaN"); | ||
}); | ||
}); | ||
describe('fail assertion', function () { | ||
@@ -481,0 +541,0 @@ it('throws an error', function () { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
194880
6185
365