@@ -328,6 +328,17 @@ describe('jsonSize', () => {
328328 expect ( actual ) . toEqual ( expected ) ;
329329 } ) ;
330330
331+ it ( 'should compute object size with Date value' , ( ) => {
332+ const value = {
333+ date : new Date ( ) ,
334+ } ;
335+
336+ const expected = JSON . stringify ( value ) . length ;
337+
338+ const actual = jsonSize ( value ) ;
339+ expect ( actual ) . toEqual ( expected ) ;
340+ } ) ;
341+
331342 it ( 'should compute object size with every key type' , ( ) => {
332343 const value = {
333344 num : 123 ,
@@ -458,6 +469,15 @@ describe('jsonSize', () => {
458469 expect ( actual ) . toEqual ( expected ) ;
459470 } ) ;
460471
472+ it ( 'should compute array size with Date value' , ( ) => {
473+ const value = [ new Date ( ) ] ;
474+
475+ const expected = JSON . stringify ( value ) . length ;
476+
477+ const actual = jsonSize ( value ) ;
478+ expect ( actual ) . toEqual ( expected ) ;
479+ } ) ;
480+
461481 it ( 'should compute array size with every value type' , ( ) => {
462482 const value = [
463483 123 ,
@@ -466,6 +486,7 @@ describe('jsonSize', () => {
466486 false ,
467487 null ,
468488 undefined ,
489+ new Date ( ) ,
469490 Symbol . for ( 'symbol' ) ,
470491 ( arg : number ) => { } ,
471492 [ '123' ] ,
@@ -507,24 +528,21 @@ describe('jsonSize', () => {
507528 expect ( actual ) . toEqual ( expected ) ;
508529 } ) ;
509530
510- // TODO: This case reports invalid size (36 vs expected 28)
511- // As most likely this will be rarely used, and the difference is not that large,
512- // I'm leaving this commented for now
513- // it('should compute object size for self-referencing object with toJSON', () => {
514- // const value = {
515- // a: {
516- // b: {
517- // toJSON() {
518- // return value;
519- // },
520- // },
521- // },
522- // };
531+ it ( 'should compute object size for self-referencing object with toJSON' , ( ) => {
532+ const value = {
533+ a : {
534+ b : {
535+ toJSON ( ) {
536+ return value ;
537+ } ,
538+ } ,
539+ } ,
540+ } ;
523541
524- // const expected = JSON.stringify(value, jsonEscaper()).length;
525- // const actual = jsonSize(value, jsonEscaper());
542+ const expected = JSON . stringify ( value , jsonEscaper ( ) ) . length ;
543+ const actual = jsonSize ( value , jsonEscaper ( ) ) ;
526544
527- // expect(actual).toEqual(expected);
528- // });
545+ expect ( actual ) . toEqual ( expected ) ;
546+ } ) ;
529547 } ) ;
530548} ) ;
0 commit comments