-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced angular.toJson with Utilities.toJson [#CanConHackathon] (#7924)
- Loading branch information
1 parent
1e851b6
commit 76e4b6b
Showing
8 changed files
with
93 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
(function () { | ||
describe("Utilities", function () { | ||
describe("toJson", function () { | ||
it("should delegate to JSON.stringify", function () { | ||
var spy = spyOn(JSON, "stringify").and.callThrough(); | ||
|
||
expect(Utilities.toJson({})).toEqual("{}"); | ||
expect(spy).toHaveBeenCalled(); | ||
}); | ||
|
||
it("should format objects pretty", function () { | ||
expect(Utilities.toJson({ a: 1, b: 2 }, true)).toBe( | ||
'{\n "a": 1,\n "b": 2\n}' | ||
); | ||
expect(Utilities.toJson({ a: { b: 2 } }, true)).toBe( | ||
'{\n "a": {\n "b": 2\n }\n}' | ||
); | ||
expect(Utilities.toJson({ a: 1, b: 2 }, false)).toBe('{"a":1,"b":2}'); | ||
expect(Utilities.toJson({ a: 1, b: 2 }, 0)).toBe('{"a":1,"b":2}'); | ||
expect(Utilities.toJson({ a: 1, b: 2 }, 1)).toBe( | ||
'{\n "a": 1,\n "b": 2\n}' | ||
); | ||
expect(Utilities.toJson({ a: 1, b: 2 }, {})).toBe( | ||
'{\n "a": 1,\n "b": 2\n}' | ||
); | ||
}); | ||
|
||
it("should not serialize properties starting with $$", function () { | ||
expect(Utilities.toJson({ $$some: "value" }, false)).toEqual("{}"); | ||
}); | ||
|
||
it("should serialize properties starting with $", function () { | ||
expect(Utilities.toJson({ $few: "v" }, false)).toEqual('{"$few":"v"}'); | ||
}); | ||
|
||
it("should not serialize $window object", function () { | ||
expect(Utilities.toJson(window)).toEqual('"$WINDOW"'); | ||
}); | ||
|
||
it("should not serialize $document object", function () { | ||
expect(Utilities.toJson(document)).toEqual('"$DOCUMENT"'); | ||
}); | ||
|
||
it("should not serialize scope instances", inject(function ( | ||
$rootScope | ||
) { | ||
expect(Utilities.toJson({ key: $rootScope })).toEqual('{"key":"$SCOPE"}'); | ||
})); | ||
|
||
it("should serialize undefined as undefined", function () { | ||
expect(Utilities.toJson(undefined)).toEqual(undefined); | ||
}); | ||
}); | ||
}); | ||
})(); |