test('if getNormalizedValue will return the circular value if an iterable that has already been processed', (t) => { const value = new Map().set('foo', 'bar').set('bar', 'baz'); const sortedCache = []; sortedCache.push(value); const result = utils.getNormalizedValue(value, sortedCache); t.deepEqual(result, CIRCULAR_VALUE); });
test('if getNormalizedValue will return the stringified buffer value if an array buffer', (t) => { const value = ARRAYBUFFER; const sortedCache = []; const result = utils.getNormalizedValue(value, sortedCache); t.is( result, utils.getPrefixedValue(Object.prototype.toString.call(value).slice(8, -1), utils.getStringifiedArrayBuffer(value)) ); });
test('if getNormalizedValue will return the HTML tag with attributes if an HTML element', (t) => { const value = document.createElement('main'); value.className = 'className'; value.id = 'id'; const sortedCache = []; const result = utils.getNormalizedValue(value, sortedCache); t.is(result, utils.getPrefixedValue(Object.prototype.toString.call(value).slice(8, -1), value.outerHTML)); });
test('if getNormalizedValue will return the sorted value passed if an object', (t) => { const value = { bar: 'baz', foo: 'bar', }; const sortedCache = []; const result = utils.getNormalizedValue(value, sortedCache); t.not(result, value); t.deepEqual(result, utils.getSortedObject(value)); });
test('if getNormalizedValue will return the circular value if an object that has already been processed', (t) => { const value = { bar: 'baz', foo: 'bar', }; const sortedCache = []; sortedCache.push(value); const result = utils.getNormalizedValue(value, sortedCache); t.not(result, value); t.deepEqual(result, CIRCULAR_VALUE); });
test('if getNormalizedValue will return the value itself if not matching', (t) => { class Foo { constructor(value) { this.value = value; return this; } get [Symbol.toStringTag]() { return 'Foo'; } } const value = new Foo('bar'); const sortedCache = []; const result = utils.getNormalizedValue(value, sortedCache); t.is(result, value); });