fix(core): Remove circular refs from Code and push msg (#5741)

* remove circular refs from code items (and lint fixes)

* cleanup

---------

* add some tests

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
Michael Auerswald
2023-03-21 15:34:30 +01:00
committed by GitHub
parent 199a91b398
commit b6d8a0f985
6 changed files with 64 additions and 12 deletions

View File

@@ -1,4 +1,4 @@
import { jsonParse, deepCopy } from '@/utils';
import { jsonParse, jsonStringify, deepCopy } from '@/utils';
describe('jsonParse', () => {
it('parses JSON', () => {
@@ -17,6 +17,21 @@ describe('jsonParse', () => {
});
});
describe('jsonStringify', () => {
const source: any = { a: 1, b: 2 };
source.c = source;
it('should throw errors on circular references by default', () => {
expect(() => jsonStringify(source)).toThrow('Converting circular structure to JSON');
});
it('should break circular references when requested', () => {
expect(jsonStringify(source, { replaceCircularRefs: true })).toEqual(
'{"a":1,"b":2,"c":"[Circular Reference]"}',
);
});
});
describe('deepCopy', () => {
it('should deep copy an object', () => {
const serializable = {