@@ -542,4 +542,54 @@ describe('angular', function() {
542542 expect ( snake_case ( 'alanBobCharles' ) ) . toEqual ( 'alan_bob_charles' ) ;
543543 } ) ;
544544 } ) ;
545+
546+
547+ describe ( 'fromJson' , function ( ) {
548+
549+ it ( 'should delegate to JSON.parse' , function ( ) {
550+ var spy = spyOn ( JSON , 'parse' ) . andCallThrough ( ) ;
551+
552+ expect ( fromJson ( '{}' ) ) . toEqual ( { } ) ;
553+ expect ( spy ) . toHaveBeenCalled ( ) ;
554+ } ) ;
555+ } ) ;
556+
557+
558+ describe ( 'toJson' , function ( ) {
559+
560+ it ( 'should delegate to JSON.stringify' , function ( ) {
561+ var spy = spyOn ( JSON , 'stringify' ) . andCallThrough ( ) ;
562+
563+ expect ( toJson ( { } ) ) . toEqual ( '{}' ) ;
564+ expect ( spy ) . toHaveBeenCalled ( ) ;
565+ } ) ;
566+
567+
568+ it ( 'should format objects pretty' , function ( ) {
569+ expect ( toJson ( { a : 1 , b : 2 } , true ) ) .
570+ toBeOneOf ( '{\n "a": 1,\n "b": 2\n}' , '{\n "a":1,\n "b":2\n}' ) ;
571+ expect ( toJson ( { a : { b : 2 } } , true ) ) .
572+ toBeOneOf ( '{\n "a": {\n "b": 2\n }\n}' , '{\n "a":{\n "b":2\n }\n}' ) ;
573+ } ) ;
574+
575+
576+ it ( 'should not serialize properties starting with $' , function ( ) {
577+ expect ( toJson ( { $few : 'v' , $$some :'value' } , false ) ) . toEqual ( '{}' ) ;
578+ } ) ;
579+
580+
581+ it ( 'should not serialize $window object' , function ( ) {
582+ expect ( toJson ( window ) ) . toEqual ( '"$WINDOW"' ) ;
583+ } ) ;
584+
585+
586+ it ( 'should not serialize $document object' , function ( ) {
587+ expect ( toJson ( document ) ) . toEqual ( '"$DOCUMENT"' ) ;
588+ } ) ;
589+
590+
591+ it ( 'should not serialize scope instances' , inject ( function ( $rootScope ) {
592+ expect ( toJson ( { key : $rootScope } ) ) . toEqual ( '{"key":"$SCOPE"}' ) ;
593+ } ) ) ;
594+ } ) ;
545595} ) ;
0 commit comments