77The ` assert ` module provides a simple set of assertion tests that can be used to
88test invariants.
99
10+ For more information about the used equality comparisons see
11+ [ MDN's guide on equality comparisons and sameness] [ mdn-equality-guide ] .
12+
1013## assert(value[ , message] )
1114<!-- YAML
1215added: v0.5.9
@@ -531,13 +534,16 @@ parameter is an instance of an `Error` then it will be thrown instead of the
531534## assert.notStrictEqual(actual, expected[ , message] )
532535<!-- YAML
533536added: v0.1.21
537+ changes:
538+ - version: REPLACEME
539+ pr-url: https://github.com/nodejs/node/pull/17003
540+ description: Used comparison changed from Strict Equality to `Object.is()`
534541-->
535542* ` actual ` {any}
536543* ` expected ` {any}
537544* ` message ` {any}
538545
539- Tests strict inequality as determined by the [ Strict Equality Comparison] [ ]
540- ( ` !== ` ).
546+ Tests equality determined by the [ ` Object.is() ` ] [ ] comparison.
541547
542548``` js
543549const assert = require (' assert' );
@@ -546,7 +552,7 @@ assert.notStrictEqual(1, 2);
546552// OK
547553
548554assert .notStrictEqual (1 , 1 );
549- // AssertionError: 1 !== 1
555+ // AssertionError: 1 notStrictEqual 1
550556
551557assert .notStrictEqual (1 , ' 1' );
552558// OK
@@ -592,25 +598,28 @@ assert.ok(false, 'it\'s false');
592598## assert.strictEqual(actual, expected[ , message] )
593599<!-- YAML
594600added: v0.1.21
601+ changes:
602+ - version: REPLACEME
603+ pr-url: https://github.com/nodejs/node/pull/17003
604+ description: Used comparison changed from Strict Equality to `Object.is()`
595605-->
596606* ` actual ` {any}
597607* ` expected ` {any}
598608* ` message ` {any}
599609
600- Tests strict equality as determined by the [ Strict Equality Comparison] [ ]
601- ( ` === ` ).
610+ Tests equality determined by the [ ` Object.is() ` ] [ ] comparison.
602611
603612``` js
604613const assert = require (' assert' );
605614
606615assert .strictEqual (1 , 2 );
607- // AssertionError: 1 === 2
616+ // AssertionError: 1 strictEqual 2
608617
609618assert .strictEqual (1 , 1 );
610619// OK
611620
612621assert .strictEqual (1 , ' 1' );
613- // AssertionError: 1 === '1'
622+ // AssertionError: 1 strictEqual '1'
614623```
615624
616625If the values are not strictly equal, an ` AssertionError ` is thrown with a
@@ -690,32 +699,6 @@ assert.throws(myFunction, 'missing foo', 'did not throw with expected message');
690699assert .throws (myFunction, / missing foo/ , ' did not throw with expected message' );
691700```
692701
693- ## Caveats
694-
695- For the following cases, consider using ES2015 [ ` Object.is() ` ] [ ] ,
696- which uses the [ SameValueZero] [ ] comparison.
697-
698- ``` js
699- const a = 0 ;
700- const b = - a;
701- assert .notStrictEqual (a, b);
702- // AssertionError: 0 !== -0
703- // Strict Equality Comparison doesn't distinguish between -0 and +0...
704- assert (! Object .is (a, b));
705- // but Object.is() does!
706-
707- const str1 = ' foo' ;
708- const str2 = ' foo' ;
709- assert .strictEqual (str1 / 1 , str2 / 1 );
710- // AssertionError: NaN === NaN
711- // Strict Equality Comparison can't be used to check NaN...
712- assert (Object .is (str1 / 1 , str2 / 1 ));
713- // but Object.is() can!
714- ```
715-
716- For more information, see
717- [ MDN's guide on equality comparisons and sameness] [ mdn-equality-guide ] .
718-
719702[ `Error.captureStackTrace` ] : errors.html#errors_error_capturestacktrace_targetobject_constructoropt
720703[ `Map` ] : https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Map
721704[ `Object.is()` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
0 commit comments