@@ -451,7 +451,7 @@ assert.doesNotThrow(function() {
451451
452452// new API, accepts an "options" object
453453{
454- let subject = { foo : 'bar' , hello : 31 , a : { b : { c : { d : 0 } } } } ;
454+ const subject = { foo : 'bar' , hello : 31 , a : { b : { c : { d : 0 } } } } ;
455455 Object . defineProperty ( subject , 'hidden' , { enumerable : false , value : null } ) ;
456456
457457 assert . strictEqual (
@@ -482,9 +482,11 @@ assert.doesNotThrow(function() {
482482 util . inspect ( subject , { depth : null } ) . includes ( '{ d: 0 }' ) ,
483483 true
484484 ) ;
485+ }
485486
487+ {
486488 // "customInspect" option can enable/disable calling inspect() on objects
487- subject = { inspect : function ( ) { return 123 ; } } ;
489+ const subject = { inspect : function ( ) { return 123 ; } } ;
488490
489491 assert . strictEqual (
490492 util . inspect ( subject , { customInspect : true } ) . includes ( '123' ) ,
@@ -515,6 +517,56 @@ assert.doesNotThrow(function() {
515517 util . inspect ( subject , { customInspectOptions : true } ) ;
516518}
517519
520+ {
521+ // "customInspect" option can enable/disable calling [util.inspect.custom]()
522+ const subject = { [ util . inspect . custom ] : function ( ) { return 123 ; } } ;
523+
524+ assert . strictEqual (
525+ util . inspect ( subject , { customInspect : true } ) . includes ( '123' ) ,
526+ true
527+ ) ;
528+ assert . strictEqual (
529+ util . inspect ( subject , { customInspect : false } ) . includes ( '123' ) ,
530+ false
531+ ) ;
532+
533+ // a custom [util.inspect.custom]() should be able to return other Objects
534+ subject [ util . inspect . custom ] = function ( ) { return { foo : 'bar' } ; } ;
535+
536+ assert . strictEqual ( util . inspect ( subject ) , '{ foo: \'bar\' }' ) ;
537+
538+ subject [ util . inspect . custom ] = function ( depth , opts ) {
539+ assert . strictEqual ( opts . customInspectOptions , true ) ;
540+ } ;
541+
542+ util . inspect ( subject , { customInspectOptions : true } ) ;
543+ }
544+
545+ {
546+ // [util.inspect.custom] takes precedence over inspect
547+ const subject = {
548+ [ util . inspect . custom ] ( ) { return 123 ; } ,
549+ inspect ( ) { return 456 ; }
550+ } ;
551+
552+ assert . strictEqual (
553+ util . inspect ( subject , { customInspect : true } ) . includes ( '123' ) ,
554+ true
555+ ) ;
556+ assert . strictEqual (
557+ util . inspect ( subject , { customInspect : false } ) . includes ( '123' ) ,
558+ false
559+ ) ;
560+ assert . strictEqual (
561+ util . inspect ( subject , { customInspect : true } ) . includes ( '456' ) ,
562+ false
563+ ) ;
564+ assert . strictEqual (
565+ util . inspect ( subject , { customInspect : false } ) . includes ( '456' ) ,
566+ false
567+ ) ;
568+ }
569+
518570// util.inspect with "colors" option should produce as many lines as without it
519571function test_lines ( input ) {
520572 var count_lines = function ( str ) {
0 commit comments