@@ -682,7 +682,7 @@ describe("javascript-stringify", () => {
682682 const result = stringify ( obj , null , null , { references : true } ) ;
683683
684684 expect ( result ) . toEqual (
685- "(function(){var x={key:'value'};x.obj=x;return x;}())"
685+ "(function(){var x={key:'value',obj:undefined };x.obj=x;return x;}())"
686686 ) ;
687687 } ) ;
688688
@@ -727,7 +727,9 @@ describe("javascript-stringify", () => {
727727
728728 const result = stringify ( obj , null , null , { references : true } ) ;
729729
730- expect ( result ) . toEqual ( "(function(){var x={a:{}};x.b=x.a;return x;}())" ) ;
730+ expect ( result ) . toEqual (
731+ "(function(){var x={a:{},b:undefined};x.b=x.a;return x;}())"
732+ ) ;
731733 } ) ;
732734
733735 it ( "should restore repeated values with indentation" , function ( ) {
@@ -740,7 +742,22 @@ describe("javascript-stringify", () => {
740742 const result = stringify ( obj , null , 2 , { references : true } ) ;
741743
742744 expect ( result ) . toEqual (
743- "(function () {\nvar x = {\n a: {}\n};\nx.b = x.a;\nreturn x;\n}())"
745+ "(function () {\nvar x = {\n a: {},\n b: undefined\n};\nx.b = x.a;\nreturn x;\n}())"
746+ ) ;
747+ } ) ;
748+
749+ it ( "should maintain key order when restoring repeated values" , ( ) => {
750+ const obj : any = { } ;
751+ const child = { } ;
752+
753+ obj . a = child ;
754+ obj . b = child ;
755+ obj . c = "C" ;
756+
757+ const result = stringify ( obj , null , null , { references : true } ) ;
758+
759+ expect ( result ) . toEqual (
760+ "(function(){var x={a:{},b:undefined,c:'C'};x.b=x.a;return x;}())"
744761 ) ;
745762 } ) ;
746763 } ) ;
0 commit comments