Skip to content

Commit

Permalink
chore: add more objects tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeed committed Feb 24, 2021
1 parent 8d0224d commit 1533843
Showing 1 changed file with 65 additions and 1 deletion.
66 changes: 65 additions & 1 deletion test/suites/objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,28 @@ export default function (dset, isMerge) {
const objects = suite('objects');
const verb = isMerge ? 'merge' : 'overwrite';

objects(`should ${verb} existing object value`, () => {
objects(`should ${verb} existing object value :: simple`, () => {
let { input } = prepare({
hello: { a: 1 }
});

dset(input, 'hello', { foo: 123 });

if (isMerge) {
assert.equal(input, {
hello: {
a: 1,
foo: 123,
}
});
} else {
assert.equal(input, {
hello: { foo: 123 }
});
}
});

objects(`should ${verb} existing object value :: nested`, () => {
let { input, copy } = prepare({
a: {
b: {
Expand All @@ -27,5 +48,48 @@ export default function (dset, isMerge) {
assert.equal(input, copy);
});

objects(`should ${verb} existing array value :: simple`, () => {
let { input } = prepare([
{ foo: 1 },
]);

dset(input, '0', { bar: 2 });

if (isMerge) {
assert.equal(input, [
{ foo: 1, bar: 2 }
]);
} else {
assert.equal(input, [
{ bar: 2 }
]);
}
});

objects(`should ${verb} existing array value :: nested`, () => {
let { input } = prepare([
{ name: 'bob', age: 56, friends: ['foobar'] },
{ name: 'alice', age: 47, friends: ['mary'] },
]);

dset(input, '0', { age: 57, friends: ['alice', 'mary'] });
dset(input, '1', { friends: ['bob'] });
dset(input, '2', { name: 'mary', age: 49, friends: ['bob'] });

if (isMerge) {
assert.equal(input, [
{ name: 'bob', age: 57, friends: ['alice', 'mary'] },
{ name: 'alice', age: 47, friends: ['bob'] },
{ name: 'mary', age: 49, friends: ['bob'] },
]);
} else {
assert.equal(input, [
{ age: 57, friends: ['alice', 'mary'] },
{ friends: ['bob'] },
{ name: 'mary', age: 49, friends: ['bob'] },
]);
}
});

objects.run();
}

0 comments on commit 1533843

Please sign in to comment.