diff --git a/lib/test.js b/lib/test.js index e1dbb8a6..bf3cbd8a 100644 --- a/lib/test.js +++ b/lib/test.js @@ -432,7 +432,6 @@ function equal(a, b, msg, extra) { Test.prototype.equal = Test.prototype.equals = Test.prototype.isEqual -= Test.prototype.is = equal; function strictEqual(a, b, msg, extra) { @@ -449,13 +448,14 @@ function strictEqual(a, b, msg, extra) { } Test.prototype.strictEqual = Test.prototype.strictEquals += Test.prototype.is = strictEqual; function notEqual(a, b, msg, extra) { if (arguments.length < 2) { throw new TypeError('two arguments must be provided to compare'); } - this._assert(a !== b, { + this._assert(a != b, { message: defined(msg, 'should not be equal'), operator: 'notEqual', actual: a, @@ -465,15 +465,29 @@ function notEqual(a, b, msg, extra) { } Test.prototype.notEqual = Test.prototype.notEquals -= Test.prototype.notStrictEqual -= Test.prototype.notStrictEquals = Test.prototype.isNotEqual -= Test.prototype.isNot -= Test.prototype.not = Test.prototype.doesNotEqual = Test.prototype.isInequal = notEqual; +function notStrictEqual(a, b, msg, extra) { + if (arguments.length < 2) { + throw new TypeError('two arguments must be provided to compare'); + } + this._assert(!is(a, b), { + message: defined(msg, 'should not be strictly equal'), + operator: 'notStrictEqual', + actual: a, + expected: b, + extra: extra + }); +} +Test.prototype.notStrictEqual += Test.prototype.notStrictEquals += Test.prototype.isNot += Test.prototype.not += notStrictEqual; + function tapeDeepEqual(a, b, msg, extra) { if (arguments.length < 2) { throw new TypeError('two arguments must be provided to compare'); diff --git a/readme.markdown b/readme.markdown index d62e64b0..756eeba1 100644 --- a/readme.markdown +++ b/readme.markdown @@ -217,17 +217,27 @@ Aliases: `t.ifError()`, `t.ifErr()`, `t.iferror()` ## t.equal(actual, expected, msg) -Assert that `actual === expected` with an optional description of the assertion `msg`. +Assert that `actual == expected` with an optional description of the assertion `msg`. -Aliases: `t.equals()`, `t.isEqual()`, `t.is()`, `t.strictEqual()`, -`t.strictEquals()` +Aliases: `t.equals()`, `t.isEqual()` + +## t.strictEqual(actual, expected, msg) + +Assert that `Object.is(actual, expected)` with an optional description of the assertion `msg`. + +Aliases: `t.is()`, `t.strictEqual()`, `t.strictEquals()` ## t.notEqual(actual, expected, msg) -Assert that `actual !== expected` with an optional description of the assertion `msg`. +Assert that `actual != expected` with an optional description of the assertion `msg`. + +Aliases: `t.notEquals()`, `t.isNotEqual()`, `t.doesNotEqual()`, `t.isInequal()` + +## t.notStrictEqual(actual, expected, msg) + +Assert that `!Object.is(actual, expected)` with an optional description of the assertion `msg`. -Aliases: `t.notEquals()`, `t.notStrictEqual()`, `t.notStrictEquals()`, -`t.isNotEqual()`, `t.isNot()`, `t.not()`, `t.doesNotEqual()`, `t.isInequal()` +Aliases: `t.notStrictEqual()`, `t.notStrictEquals()`, `t.isNot()`, `t.not()` ## t.deepEqual(actual, expected, msg) diff --git a/test/edge-cases.js b/test/edge-cases.js index 5840ad63..00b0072c 100644 --- a/test/edge-cases.js +++ b/test/edge-cases.js @@ -17,7 +17,35 @@ tap.test('edge cases', function (tt) { + '# zeroes\n' + 'ok 1 0 equal to -0\n' + 'ok 2 -0 equal to 0\n' - + 'not ok 3 0 strictEqual to -0\n' + + 'not ok 3 0 notEqual to -0\n' + + ' ---\n' + + ' operator: notEqual\n' + + ' expected: |-\n' + + ' -0\n' + + ' actual: |-\n' + + ' 0\n' + + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: 0 notEqual to -0\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'not ok 4 -0 notEqual to 0\n' + + ' ---\n' + + ' operator: notEqual\n' + + ' expected: |-\n' + + ' 0\n' + + ' actual: |-\n' + + ' -0\n' + + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: -0 notEqual to 0\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'not ok 5 0 strictEqual to -0\n' + ' ---\n' + ' operator: strictEqual\n' + ' expected: |-\n' @@ -31,7 +59,7 @@ tap.test('edge cases', function (tt) { + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + ' [... stack stripped ...]\n' + ' ...\n' - + 'not ok 4 -0 strictEqual to 0\n' + + 'not ok 6 -0 strictEqual to 0\n' + ' ---\n' + ' operator: strictEqual\n' + ' expected: |-\n' @@ -45,9 +73,39 @@ tap.test('edge cases', function (tt) { + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + ' [... stack stripped ...]\n' + ' ...\n' - + 'ok 5 0 deepLooseEqual to -0\n' - + 'ok 6 -0 deepLooseEqual to 0\n' - + 'not ok 7 0 deepEqual to -0\n' + + 'ok 7 0 notStrictEqual to -0\n' + + 'ok 8 -0 notStrictEqual to 0\n' + + 'ok 9 0 deepLooseEqual to -0\n' + + 'ok 10 -0 deepLooseEqual to 0\n' + + 'not ok 11 0 notDeepLooseEqual to -0\n' + + ' ---\n' + + ' operator: notDeepLooseEqual\n' + + ' expected: |-\n' + + ' -0\n' + + ' actual: |-\n' + + ' 0\n' + + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: 0 notDeepLooseEqual to -0\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'not ok 12 -0 notDeepLooseEqual to 0\n' + + ' ---\n' + + ' operator: notDeepLooseEqual\n' + + ' expected: |-\n' + + ' 0\n' + + ' actual: |-\n' + + ' -0\n' + + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: -0 notDeepLooseEqual to 0\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'not ok 13 0 deepEqual to -0\n' + ' ---\n' + ' operator: deepEqual\n' + ' expected: |-\n' @@ -61,7 +119,7 @@ tap.test('edge cases', function (tt) { + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + ' [... stack stripped ...]\n' + ' ...\n' - + 'not ok 8 -0 deepEqual to 0\n' + + 'not ok 14 -0 deepEqual to 0\n' + ' ---\n' + ' operator: deepEqual\n' + ' expected: |-\n' @@ -75,8 +133,10 @@ tap.test('edge cases', function (tt) { + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + ' [... stack stripped ...]\n' + ' ...\n' + + 'ok 15 0 notDeepEqual to -0\n' + + 'ok 16 -0 notDeepEqual to 0\n' + '# NaNs\n' - + 'not ok 9 NaN equal to NaN\n' + + 'not ok 17 NaN equal to NaN\n' + ' ---\n' + ' operator: equal\n' + ' expected: NaN\n' @@ -88,8 +148,21 @@ tap.test('edge cases', function (tt) { + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + ' [... stack stripped ...]\n' + ' ...\n' - + 'ok 10 NaN strictEqual to NaN\n' - + 'not ok 11 NaN deepLooseEqual to NaN\n' + + 'ok 18 NaN notEqual to NaN\n' + + 'ok 19 NaN strictEqual to NaN\n' + + 'not ok 20 NaN notStrictEqual to NaN\n' + + ' ---\n' + + ' operator: notStrictEqual\n' + + ' expected: NaN\n' + + ' actual: NaN\n' + + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: NaN notStrictEqual to NaN\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'not ok 21 NaN deepLooseEqual to NaN\n' + ' ---\n' + ' operator: deepLooseEqual\n' + ' expected: NaN\n' @@ -101,38 +174,63 @@ tap.test('edge cases', function (tt) { + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + ' [... stack stripped ...]\n' + ' ...\n' - + 'ok 12 NaN deepEqual to NaN\n' - + '\n1..12\n' - + '# tests 12\n' - + '# pass 6\n' - + '# fail 6\n' + + 'ok 22 NaN notDeepLooseEqual to NaN\n' + + 'ok 23 NaN deepEqual to NaN\n' + + 'not ok 24 NaN notDeepEqual to NaN\n' + + ' ---\n' + + ' operator: notDeepEqual\n' + + ' expected: NaN\n' + + ' actual: NaN\n' + + ' at: Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: NaN notDeepEqual to NaN\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/edge-cases.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + '\n1..24\n' + + '# tests 24\n' + + '# pass 12\n' + + '# fail 12\n' ); })); test('zeroes', function (t) { t.equal(0, -0, '0 equal to -0'); t.equal(-0, 0, '-0 equal to 0'); + t.notEqual(0, -0, '0 notEqual to -0'); + t.notEqual(-0, 0, '-0 notEqual to 0'); t.strictEqual(0, -0, '0 strictEqual to -0'); t.strictEqual(-0, 0, '-0 strictEqual to 0'); + t.notStrictEqual(0, -0, '0 notStrictEqual to -0'); + t.notStrictEqual(-0, 0, '-0 notStrictEqual to 0'); t.deepLooseEqual(0, -0, '0 deepLooseEqual to -0'); t.deepLooseEqual(-0, 0, '-0 deepLooseEqual to 0'); + t.notDeepLooseEqual(0, -0, '0 notDeepLooseEqual to -0'); + t.notDeepLooseEqual(-0, 0, '-0 notDeepLooseEqual to 0'); t.deepEqual(0, -0, '0 deepEqual to -0'); t.deepEqual(-0, 0, '-0 deepEqual to 0'); + t.notDeepEqual(0, -0, '0 notDeepEqual to -0'); + t.notDeepEqual(-0, 0, '-0 notDeepEqual to 0'); t.end(); }); test('NaNs', function (t) { t.equal(NaN, NaN, 'NaN equal to NaN'); + t.notEqual(NaN, NaN, 'NaN notEqual to NaN'); t.strictEqual(NaN, NaN, 'NaN strictEqual to NaN'); + t.notStrictEqual(NaN, NaN, 'NaN notStrictEqual to NaN'); t.deepLooseEqual(NaN, NaN, 'NaN deepLooseEqual to NaN'); + t.notDeepLooseEqual(NaN, NaN, 'NaN notDeepLooseEqual to NaN'); t.deepEqual(NaN, NaN, 'NaN deepEqual to NaN'); + t.notDeepEqual(NaN, NaN, 'NaN notDeepEqual to NaN'); t.end(); }); diff --git a/test/numerics.js b/test/numerics.js index 19392c18..7c3f7554 100644 --- a/test/numerics.js +++ b/test/numerics.js @@ -17,7 +17,31 @@ tap.test('numerics', function (tt) { + '# numeric strings\n' + 'ok 1 number equal to string\n' + 'ok 2 string equal to number\n' - + 'not ok 3 number strictEqual to string\n' + + 'not ok 3 number notEqual to string\n' + + ' ---\n' + + ' operator: notEqual\n' + + ' expected: \'3\'\n' + + ' actual: 3\n' + + ' at: Test. ($TEST/numerics.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: number notEqual to string\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/numerics.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'not ok 4 string notEqual to number\n' + + ' ---\n' + + ' operator: notEqual\n' + + ' expected: 3\n' + + ' actual: \'3\'\n' + + ' at: Test. ($TEST/numerics.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: string notEqual to number\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/numerics.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'not ok 5 number strictEqual to string\n' + ' ---\n' + ' operator: strictEqual\n' + ' expected: \'3\'\n' @@ -29,7 +53,7 @@ tap.test('numerics', function (tt) { + ' at Test. ($TEST/numerics.js:$LINE:$COL)\n' + ' [... stack stripped ...]\n' + ' ...\n' - + 'not ok 4 string strictEqual to number\n' + + 'not ok 6 string strictEqual to number\n' + ' ---\n' + ' operator: strictEqual\n' + ' expected: 3\n' @@ -41,9 +65,35 @@ tap.test('numerics', function (tt) { + ' at Test. ($TEST/numerics.js:$LINE:$COL)\n' + ' [... stack stripped ...]\n' + ' ...\n' - + 'ok 5 number deepLooseEqual to string\n' - + 'ok 6 string deepLooseEqual to number\n' - + 'not ok 7 number deepEqual to string\n' + + 'ok 7 number notStrictEqual to string\n' + + 'ok 8 string notStrictEqual to number\n' + + 'ok 9 number deepLooseEqual to string\n' + + 'ok 10 string deepLooseEqual to number\n' + + 'not ok 11 number notDeepLooseEqual to string\n' + + ' ---\n' + + ' operator: notDeepLooseEqual\n' + + ' expected: \'3\'\n' + + ' actual: 3\n' + + ' at: Test. ($TEST/numerics.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: number notDeepLooseEqual to string\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/numerics.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'not ok 12 string notDeepLooseEqual to number\n' + + ' ---\n' + + ' operator: notDeepLooseEqual\n' + + ' expected: 3\n' + + ' actual: \'3\'\n' + + ' at: Test. ($TEST/numerics.js:$LINE:$COL)\n' + + ' stack: |-\n' + + ' Error: string notDeepLooseEqual to number\n' + + ' [... stack stripped ...]\n' + + ' at Test. ($TEST/numerics.js:$LINE:$COL)\n' + + ' [... stack stripped ...]\n' + + ' ...\n' + + 'not ok 13 number deepEqual to string\n' + ' ---\n' + ' operator: deepEqual\n' + ' expected: \'3\'\n' @@ -55,7 +105,7 @@ tap.test('numerics', function (tt) { + ' at Test. ($TEST/numerics.js:$LINE:$COL)\n' + ' [... stack stripped ...]\n' + ' ...\n' - + 'not ok 8 string deepEqual to number\n' + + 'not ok 14 string deepEqual to number\n' + ' ---\n' + ' operator: deepEqual\n' + ' expected: 3\n' @@ -67,25 +117,35 @@ tap.test('numerics', function (tt) { + ' at Test. ($TEST/numerics.js:$LINE:$COL)\n' + ' [... stack stripped ...]\n' + ' ...\n' - + '\n1..8\n' - + '# tests 8\n' - + '# pass 4\n' - + '# fail 4\n' + + 'ok 15 number notDeepEqual to string\n' + + 'ok 16 string notDeepEqual to number\n' + + '\n1..16\n' + + '# tests 16\n' + + '# pass 8\n' + + '# fail 8\n' ); })); test('numeric strings', function (t) { t.equal(3, '3', 'number equal to string'); t.equal('3', 3, 'string equal to number'); + t.notEqual(3, '3', 'number notEqual to string'); + t.notEqual('3', 3, 'string notEqual to number'); t.strictEqual(3, '3', 'number strictEqual to string'); t.strictEqual('3', 3, 'string strictEqual to number'); + t.notStrictEqual(3, '3', 'number notStrictEqual to string'); + t.notStrictEqual('3', 3, 'string notStrictEqual to number'); t.deepLooseEqual(3, '3', 'number deepLooseEqual to string'); t.deepLooseEqual('3', 3, 'string deepLooseEqual to number'); + t.notDeepLooseEqual(3, '3', 'number notDeepLooseEqual to string'); + t.notDeepLooseEqual('3', 3, 'string notDeepLooseEqual to number'); t.deepEqual(3, '3', 'number deepEqual to string'); t.deepEqual('3', 3, 'string deepEqual to number'); + t.notDeepEqual(3, '3', 'number notDeepEqual to string'); + t.notDeepEqual('3', 3, 'string notDeepEqual to number'); t.end(); });