@@ -478,3 +478,163 @@ test('Assert class non strict with simple diff', () => {
478478 ) ;
479479 }
480480} ) ;
481+
482+ // Shared setup for skipPrototype tests
483+ {
484+ const message = 'Expected values to be strictly deep-equal:\n' +
485+ '+ actual - expected\n' +
486+ '\n' +
487+ ' [\n' +
488+ ' 1,\n' +
489+ ' 2,\n' +
490+ ' 3,\n' +
491+ ' 4,\n' +
492+ ' 5,\n' +
493+ '+ 6,\n' +
494+ '- 9,\n' +
495+ ' 7\n' +
496+ ' ]\n' ;
497+
498+ function CoolClass ( name ) { this . name = name ; }
499+
500+ function AwesomeClass ( name ) { this . name = name ; }
501+
502+ class Modern { constructor ( value ) { this . value = value ; } }
503+ class Legacy { constructor ( value ) { this . value = value ; } }
504+
505+ const cool = new CoolClass ( 'Assert is inspiring' ) ;
506+ const awesome = new AwesomeClass ( 'Assert is inspiring' ) ;
507+ const modern = new Modern ( 42 ) ;
508+ const legacy = new Legacy ( 42 ) ;
509+
510+ test ( 'Assert class strict with skipPrototype' , ( ) => {
511+ const assertInstance = new Assert ( { skipPrototype : true } ) ;
512+
513+ assert . throws (
514+ ( ) => assertInstance . deepEqual ( [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] , [ 1 , 2 , 3 , 4 , 5 , 9 , 7 ] ) ,
515+ { message }
516+ ) ;
517+
518+ assertInstance . deepEqual ( cool , awesome ) ;
519+ assertInstance . deepStrictEqual ( cool , awesome ) ;
520+ assertInstance . deepEqual ( modern , legacy ) ;
521+ assertInstance . deepStrictEqual ( modern , legacy ) ;
522+
523+ const cool2 = new CoolClass ( 'Soooo coooool' ) ;
524+ assert . throws (
525+ ( ) => assertInstance . deepStrictEqual ( cool , cool2 ) ,
526+ { code : 'ERR_ASSERTION' }
527+ ) ;
528+
529+ const nested1 = { obj : new CoolClass ( 'test' ) , arr : [ 1 , 2 , 3 ] } ;
530+ const nested2 = { obj : new AwesomeClass ( 'test' ) , arr : [ 1 , 2 , 3 ] } ;
531+ assertInstance . deepStrictEqual ( nested1 , nested2 ) ;
532+
533+ const arr = new Uint8Array ( [ 1 , 2 , 3 ] ) ;
534+ const buf = Buffer . from ( [ 1 , 2 , 3 ] ) ;
535+ assertInstance . deepStrictEqual ( arr , buf ) ;
536+ } ) ;
537+
538+ test ( 'Assert class non strict with skipPrototype' , ( ) => {
539+ const assertInstance = new Assert ( { strict : false , skipPrototype : true } ) ;
540+
541+ assert . throws (
542+ ( ) => assertInstance . deepStrictEqual ( [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] , [ 1 , 2 , 3 , 4 , 5 , 9 , 7 ] ) ,
543+ { message }
544+ ) ;
545+
546+ assertInstance . deepStrictEqual ( cool , awesome ) ;
547+ assertInstance . deepStrictEqual ( modern , legacy ) ;
548+ } ) ;
549+
550+ test ( 'Assert class skipPrototype with complex objects' , ( ) => {
551+ const assertInstance = new Assert ( { skipPrototype : true } ) ;
552+
553+ function ComplexAwesomeClass ( name , age ) {
554+ this . name = name ;
555+ this . age = age ;
556+ this . settings = {
557+ theme : 'dark' ,
558+ lang : 'en'
559+ } ;
560+ }
561+
562+ function ComplexCoolClass ( name , age ) {
563+ this . name = name ;
564+ this . age = age ;
565+ this . settings = {
566+ theme : 'dark' ,
567+ lang : 'en'
568+ } ;
569+ }
570+
571+ const awesome1 = new ComplexAwesomeClass ( 'Foo' , 30 ) ;
572+ const cool1 = new ComplexCoolClass ( 'Foo' , 30 ) ;
573+
574+ assertInstance . deepStrictEqual ( awesome1 , cool1 ) ;
575+
576+ const cool2 = new ComplexCoolClass ( 'Foo' , 30 ) ;
577+ cool2 . settings . theme = 'light' ;
578+
579+ assert . throws (
580+ ( ) => assertInstance . deepStrictEqual ( awesome1 , cool2 ) ,
581+ { code : 'ERR_ASSERTION' }
582+ ) ;
583+ } ) ;
584+
585+ test ( 'Assert class skipPrototype with arrays and special objects' , ( ) => {
586+ const assertInstance = new Assert ( { skipPrototype : true } ) ;
587+
588+ const arr1 = [ 1 , 2 , 3 ] ;
589+ const arr2 = new Array ( 1 , 2 , 3 ) ;
590+ assertInstance . deepStrictEqual ( arr1 , arr2 ) ;
591+
592+ const date1 = new Date ( '2023-01-01' ) ;
593+ const date2 = new Date ( '2023-01-01' ) ;
594+ assertInstance . deepStrictEqual ( date1 , date2 ) ;
595+
596+ const regex1 = / t e s t / g;
597+ const regex2 = new RegExp ( 'test' , 'g' ) ;
598+ assertInstance . deepStrictEqual ( regex1 , regex2 ) ;
599+
600+ const date3 = new Date ( '2023-01-02' ) ;
601+ assert . throws (
602+ ( ) => assertInstance . deepStrictEqual ( date1 , date3 ) ,
603+ { code : 'ERR_ASSERTION' }
604+ ) ;
605+ } ) ;
606+
607+ test ( 'Assert class skipPrototype with notDeepStrictEqual' , ( ) => {
608+ const assertInstance = new Assert ( { skipPrototype : true } ) ;
609+
610+ assert . throws (
611+ ( ) => assertInstance . notDeepStrictEqual ( cool , awesome ) ,
612+ { code : 'ERR_ASSERTION' }
613+ ) ;
614+
615+ const notAwesome = new AwesomeClass ( 'Not so awesome' ) ;
616+ assertInstance . notDeepStrictEqual ( cool , notAwesome ) ;
617+
618+ const defaultAssertInstance = new Assert ( { skipPrototype : false } ) ;
619+ defaultAssertInstance . notDeepStrictEqual ( cool , awesome ) ;
620+ } ) ;
621+
622+ test ( 'Assert class skipPrototype with mixed types' , ( ) => {
623+ const assertInstance = new Assert ( { skipPrototype : true } ) ;
624+
625+ const obj1 = { value : 42 , nested : { prop : 'test' } } ;
626+
627+ function CustomObj ( value , nested ) {
628+ this . value = value ;
629+ this . nested = nested ;
630+ }
631+
632+ const obj2 = new CustomObj ( 42 , { prop : 'test' } ) ;
633+ assertInstance . deepStrictEqual ( obj1 , obj2 ) ;
634+
635+ assert . throws (
636+ ( ) => assertInstance . deepStrictEqual ( { num : 42 } , { num : '42' } ) ,
637+ { code : 'ERR_ASSERTION' }
638+ ) ;
639+ } ) ;
640+ }
0 commit comments