Skip to content

Commit

Permalink
chore: addl "full" test suites
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeed committed Aug 14, 2020
1 parent 2788879 commit 0110463
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test/full.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ suites.Sets(klona);
suites.TypedArrays(klona);

suites.Symbols(klona);
// suites.Descriptors(klona);
suites.Descriptors(klona);
suites.Dicts(klona);
78 changes: 78 additions & 0 deletions test/suites/descriptor.js
Original file line number Diff line number Diff line change
@@ -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();
}
32 changes: 32 additions & 0 deletions test/suites/dictionary.js
Original file line number Diff line number Diff line change
@@ -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();
}
2 changes: 2 additions & 0 deletions test/suites/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down

0 comments on commit 0110463

Please sign in to comment.