-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
25 lines (18 loc) · 1.02 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { replaceCircularObject } from '../src/index.js';
import assert from 'node:assert';
const circularObject = {};
circularObject.property = circularObject;
const circularArray = [];
circularArray.push(circularArray);
const replacedObjectNoDefault = replaceCircularObject(circularObject);
assert.deepEqual(replacedObjectNoDefault, { property: {} });
const replacedObjectWithDefault = replaceCircularObject(circularObject, 'Default Value!', 3);
assert.deepEqual(replacedObjectWithDefault, { property: { property: { property: 'Default Value!' } } });
const replacedArrayNoDefault = replaceCircularObject(circularArray);
assert.deepEqual(replacedArrayNoDefault, [[]]);
const replacedArrayWithDepth = replaceCircularObject(circularArray, undefined, 5);
assert.deepEqual(replacedArrayWithDepth, [[[[[[]]]]]]);
console.log('----------------------------------------------');
console.log('🚀🚀🚀🚀🚀 ESModules tests passed! 🚀🚀🚀🚀🚀');
console.log('----------------------------------------------');
console.log('');