@@ -111,7 +111,25 @@ testObjects["Multireference"] = () => {
111111 return obj ;
112112} ;
113113
114- console . log ( "💫 Starting js-testdiff unit tests:" )
114+ console . log ( "💫 Starting js-testdiff unit tests:" ) ;
115+ unitTest ( "should return true when two primitives differ" , function ( expect ) {
116+ expect ( testDiff ( undefined , null ) ) . toBe ( true ) ;
117+ expect ( testDiff ( 1 , 2 ) ) . toBe ( true ) ;
118+ expect ( testDiff ( true , false ) ) . toBe ( true ) ;
119+ expect ( testDiff ( "AB" , "CD" ) ) . toBe ( true ) ;
120+ expect ( testDiff ( NaN , 1 ) ) . toBe ( true ) ;
121+ expect ( testDiff ( Symbol ( "Test1" ) , Symbol ( "Test2" ) ) ) . toBe ( true ) ;
122+ } ) ;
123+ unitTest ( "should return false when two primitives are the same" , function ( expect ) {
124+ expect ( testDiff ( undefined , undefined ) ) . toBe ( false ) ;
125+ expect ( testDiff ( 1 , 1 ) ) . toBe ( false ) ;
126+ expect ( testDiff ( true , true ) ) . toBe ( false ) ;
127+ expect ( testDiff ( "AB" , "AB" ) ) . toBe ( false ) ;
128+ expect ( testDiff ( NaN , NaN ) ) . toBe ( false ) ;
129+ const sym = Symbol ( "Test" ) ;
130+ expect ( testDiff ( sym , sym ) ) . toBe ( false ) ;
131+ } ) ;
132+ const startTime = performance . now ( ) ;
115133// Fun Fact: Opossums groom themselves and are quite clean.
116134unitTest ( "should return true when two objects differ" , function ( expect ) {
117135 const testObject = testObjects [ "Nested Acyclic" ] ( ) ;
@@ -123,6 +141,7 @@ unitTest("should return true when two objects differ", function (expect) {
123141 expect ( testDiff ( testObjects [ "Nested Cyclic" ] ( ) , testObjects [ "Nested Acyclic" ] ( ) ) ) . toBe ( true ) ;
124142} ) ;
125143unitTest ( "should return false when two objects are the same" , function ( expect ) {
144+ expect ( testDiff ( null , null ) ) . toBe ( false ) ;
126145 expect ( testDiff ( testObjects [ "Linear Acyclic" ] ( ) , testObjects [ "Linear Acyclic" ] ( ) ) ) . toBe ( false ) ;
127146 expect ( testDiff ( testObjects [ "Linear Cyclic" ] ( ) , testObjects [ "Linear Cyclic" ] ( ) ) ) . toBe ( false ) ;
128147 expect ( testDiff ( testObjects [ "Multidimensional Acyclic" ] ( ) , testObjects [ "Multidimensional Acyclic" ] ( ) ) ) . toBe ( false ) ;
@@ -134,4 +153,5 @@ unitTest("should ignore deep differences when traversal is disabled", function (
134153 const testObject = testObjects [ "Nested Acyclic" ] ( ) ;
135154 testObject [ 2 ] [ 2 ] [ 0 ] = "This difference should NOT be detected." ;
136155 expect ( testDiff ( testObject , testObjects [ "Nested Acyclic" ] ( ) , false ) ) . toBe ( false ) ;
137- } ) ;
156+ } ) ;
157+ console . log ( `Unit tests finished in ${ ( performance . now ( ) - startTime ) . toFixed ( 3 ) } ms.` ) ;
0 commit comments