diff --git a/test/full.js b/test/full.js index 8d58945..816a9b7 100644 --- a/test/full.js +++ b/test/full.js @@ -24,4 +24,5 @@ suites.Sets(klona); suites.TypedArrays(klona); suites.Symbols(klona); -// suites.Descriptors(klona); +suites.Descriptors(klona); +suites.Dicts(klona); diff --git a/test/suites/descriptor.js b/test/suites/descriptor.js new file mode 100644 index 0000000..d925bbb --- /dev/null +++ b/test/suites/descriptor.js @@ -0,0 +1,78 @@ +import { suite } from 'uvu'; +import * as assert from 'assert'; + +export default function (klona) { + const Descriptors = suite('Descriptor'); + + Descriptors('hidden', () => { + const input = { foo: 123 }; + Object.defineProperty(input, 'bar', { + enumerable: false, + value: [1, 2, 3] + }); + + const output = klona(input); + assert.deepEqual(input, output); + + assert.deepEqual( + Object.getOwnPropertyDescriptor(output, 'bar'), + { + enumerable: false, + configurable: false, + writable: false, + value: [1, 2, 3] + } + ); + + output.bar.push('howdy'); + assert.deepEqual(input.bar, [1, 2, 3]); + }); + + Descriptors('hidden writable configurable', () => { + const input = { foo: 123 }; + Object.defineProperty(input, 'bar', { + enumerable: false, + configurable: true, + writable: true, + value: [1, 2, 3] + }); + + const output = klona(input); + assert.deepEqual(input, output); + + assert.deepEqual( + Object.getOwnPropertyDescriptor(output, 'bar'), + { + enumerable: false, + configurable: true, + writable: true, + value: [1, 2, 3] + } + ); + + output.bar.push('howdy'); + assert.deepEqual(input.bar, [1, 2, 3]); + }); + + Descriptors('hidden getter', () => { + const input = { foo: 123 }; + Object.defineProperty(input, 'bar', { + enumerable: false, + get() { + return [1, 2, 3] + } + }); + + const output = klona(input); + assert.deepEqual(input, output); + + const xyz = Object.getOwnPropertyDescriptor(output, 'bar'); + assert.equal(typeof xyz.get, 'function'); + + output.bar.push('howdy'); + assert.deepEqual(input.bar, [1, 2, 3]); + assert.deepEqual(output.bar, [1, 2, 3]); + }); + + Descriptors.run(); +} diff --git a/test/suites/dictionary.js b/test/suites/dictionary.js new file mode 100644 index 0000000..05ddba1 --- /dev/null +++ b/test/suites/dictionary.js @@ -0,0 +1,32 @@ +import { suite } from 'uvu'; +import * as assert from 'assert'; + +export default function (klona) { + const Dictionarys = suite('Dictionary'); + + Dictionarys('dictionary :: empty', () => { + const input = Object.create(null); + + let output = klona(input); + assert.deepEqual(input, output); + assert.equal(output.constructor, undefined); + + output.foo = 123; + assert.equal(input.foo, undefined); + }); + + Dictionarys('dictionary :: values', () => { + const input = Object.create(null); + input.hello = 'world'; + input.list = [1, 2, 3]; + + let output = klona(input); + assert.deepEqual(input, output); + assert.equal(output.constructor, undefined); + + output.list.push('howdy'); + assert.deepEqual(input.list, [1, 2, 3]); + }); + + Dictionarys.run(); +} diff --git a/test/suites/index.js b/test/suites/index.js index 7b8c288..7d5ccfc 100644 --- a/test/suites/index.js +++ b/test/suites/index.js @@ -9,11 +9,13 @@ export { default as Maps } from './map'; export { default as Sets } from './set'; export { default as TypedArrays } from './typedarray'; +export { default as Descriptors } from './descriptor'; export { default as Symbols } from './symbol'; export { default as Dates } from './date'; export { default as RegExps } from './regexp'; +export { default as Dicts } from './dictionary'; export { default as Objects } from './object'; export { default as Arrays } from './array';