mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-01-12 22:45:52 +08:00
Fix the JSON stringification to output a more meaningful string when an object cannot be normally converted to a JSON string, such as when the object contains cyclic references that would cause `JSON.stringify()` to throw an error. Closes #10085
16 lines
614 B
JavaScript
16 lines
614 B
JavaScript
'use strict';
|
|
|
|
describe('toDebugString', function() {
|
|
it('should convert its argument to a string', function() {
|
|
expect(toDebugString('string')).toEqual('string');
|
|
expect(toDebugString(123)).toEqual('123');
|
|
expect(toDebugString({a:{b:'c'}})).toEqual('{"a":{"b":"c"}}');
|
|
expect(toDebugString(function fn() { var a = 10; })).toEqual('function fn()');
|
|
expect(toDebugString()).toEqual('undefined');
|
|
var a = { };
|
|
a.a = a;
|
|
expect(toDebugString(a)).toEqual('{"a":"<<already seen>>"}');
|
|
expect(toDebugString([a,a])).toEqual('[{"a":"<<already seen>>"},"<<already seen>>"]');
|
|
});
|
|
});
|