-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump package versions and deprecate node 6
Signed-off-by: João Ferreira <[email protected]>
- Loading branch information
Showing
7 changed files
with
753 additions
and
537 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"extends": "airbnb-base", | ||
"extends": "conversio", | ||
"env": { | ||
"node": true, | ||
"es6": true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
language: node_js | ||
node_js: | ||
- '12' | ||
- '10' | ||
- '8' | ||
- '6' | ||
script: | ||
- npm run lint | ||
- npm test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,112 @@ | ||
'use strict'; | ||
|
||
const should = require('should'), | ||
sinon = require('sinon'), | ||
test = require('ava').test, | ||
objOps = require('../../lib/objectOps'); | ||
|
||
const ObjectOps = objOps.ObjectOps; | ||
|
||
test('#constructor can initialize from another object', () => { | ||
should(new ObjectOps({ a: 1, b: { c: 2 } })) | ||
.containEql({ a: 1, b: { c: 2 } }); | ||
const sinon = require('sinon'), | ||
{ test } = require('ava'), | ||
{ ObjectOps } = require('../../lib/objectOps'); | ||
|
||
test('#constructor can initialize from another object', t => { | ||
t.deepEqual( | ||
Object.assign({}, new ObjectOps({ a: 1, b: { c: 2 } })), | ||
{ a: 1, b: { c: 2 } } | ||
); | ||
}); | ||
|
||
test('#clone returns a deep copy of the object', () => { | ||
test('#clone returns a deep copy of the object', t => { | ||
const base = new ObjectOps({ a: 1, b: { c: 2 } }); | ||
const clone = base.clone(); | ||
|
||
should(base).eql(clone); | ||
should(base).not.equal(clone); | ||
should(base.b).not.equal(clone.b); | ||
t.deepEqual(base, clone); | ||
t.not(base, clone); | ||
t.not(base.b, clone.b); | ||
}); | ||
|
||
test('#move copies the value from one path to another', () => { | ||
should(new ObjectOps({ a: 1, b: { c: 2 } }).move('b.c', 'b.d')) | ||
.eql(new ObjectOps({ a: 1, b: { d: 2 } })); | ||
test('#move copies the value from one path to another', t => { | ||
t.deepEqual( | ||
new ObjectOps({ a: 1, b: { c: 2 } }).move('b.c', 'b.d'), | ||
new ObjectOps({ a: 1, b: { d: 2 } }) | ||
); | ||
}); | ||
|
||
test('#move errors out if source path does not exist', () => { | ||
should(() => new ObjectOps({ a: 1, b: { c: 2 } }).move('c.c', 'b.c')) | ||
.throw(TypeError, { message: 'Path is invalid at depth 0.' }); | ||
test('#move errors out if source path does not exist', t => { | ||
t.throws( | ||
() => new ObjectOps({ a: 1, b: { c: 2 } }).move('c.c', 'b.c'), | ||
TypeError, | ||
'Path is invalid at depth 0.' | ||
); | ||
}); | ||
|
||
test('#move builds the new path as needed', () => { | ||
should(new ObjectOps({ a: 1, b: { c: 2 } }).move('b.c', 'c.b')) | ||
.containEql({ c: { b: 2 } }); | ||
test('#move builds the new path as needed', t => { | ||
t.deepEqual( | ||
new ObjectOps({ a: 1, b: { c: 2 } }).move('b.c', 'c.b').c, | ||
{ b: 2 } | ||
); | ||
}); | ||
|
||
test('#move fails if destination path exists and is not traversable', () => { | ||
should(() => new ObjectOps({ a: 1, b: { c: 2 } }).move('b.c', 'a.b')) | ||
.throw(TypeError, { message: 'Path not traversable on step "a". Expected Object, got "1".' }); | ||
test('#move fails if destination path exists and is not traversable', t => { | ||
t.throws( | ||
() => new ObjectOps({ a: 1, b: { c: 2 } }).move('b.c', 'a.b'), | ||
TypeError, | ||
'Path not traversable on step "a". Expected Object, got "1".' | ||
); | ||
}); | ||
|
||
test('#move removes the source value', () => { | ||
should(new ObjectOps({ a: 1, b: { c: 2 } }).move('b.c', 'c.b')) | ||
.containEql({ b: {} }); | ||
test('#move removes the source value', t => { | ||
t.deepEqual( | ||
new ObjectOps({ a: 1, b: { c: 2 } }).move('b.c', 'c.b').b, | ||
{} | ||
); | ||
}); | ||
|
||
test('#move leaves the object untouched if an error occurs', () => { | ||
test('#move leaves the object untouched if an error occurs', t => { | ||
const obj = new ObjectOps({ a: 1, b: { c: 2 } }); | ||
|
||
try { | ||
obj.move('b.c', 'a.b'); | ||
} catch (err) { | ||
should(obj).eql(new ObjectOps({ a: 1, b: { c: 2 } })); | ||
t.deepEqual(obj, new ObjectOps({ a: 1, b: { c: 2 } })); | ||
} | ||
}); | ||
|
||
test('#remove removes a path from the object', () => { | ||
should(new ObjectOps({ a: 1, b: { c: 2 } }).remove('b.c')) | ||
.eql(new ObjectOps({ a: 1, b: { } })); | ||
test('#remove removes a path from the object', t => { | ||
t.deepEqual( | ||
new ObjectOps({ a: 1, b: { c: 2 } }).remove('b.c'), | ||
new ObjectOps({ a: 1, b: { } }) | ||
); | ||
}); | ||
|
||
test('#remove errors out if path doesn\'t exist', () => { | ||
should(() => new ObjectOps({ a: 1, b: { c: 2 } }).remove('a.b')) | ||
.throw(TypeError, { message: 'Expected object, got "1".' }); | ||
test('#remove errors out if path doesn\'t exist', t => { | ||
t.throws( | ||
() => new ObjectOps({ a: 1, b: { c: 2 } }).remove('a.b'), | ||
TypeError, | ||
'Expected object, got "1".' | ||
); | ||
}); | ||
|
||
test('#remove takes multiple paths', () => { | ||
should(new ObjectOps({ a: 1, b: { c: 2 } }).remove('a', 'b')) | ||
.eql(new ObjectOps()); | ||
test('#remove takes multiple paths', t => { | ||
t.deepEqual( | ||
new ObjectOps({ a: 1, b: { c: 2 } }).remove('a', 'b'), | ||
new ObjectOps() | ||
); | ||
}); | ||
|
||
test('#transform calls a function with the value at path', () => { | ||
test('#transform calls a function with the value at path', t => { | ||
const spy = sinon.spy(() => {}); | ||
new ObjectOps({ a: 1, b: { c: 2 } }).transform('b.c', spy); | ||
sinon.assert.calledWith(spy, 2); | ||
t.pass(); | ||
}); | ||
|
||
test('#transform sets the value returned from the function', () => { | ||
should(new ObjectOps({ a: 1, b: { c: 2 } }).transform('b.c', () => 3)) | ||
.eql(new ObjectOps({ a: 1, b: { c: 3 } })); | ||
test('#transform sets the value returned from the function', t => { | ||
t.deepEqual( | ||
new ObjectOps({ a: 1, b: { c: 2 } }).transform('b.c', () => 3), | ||
new ObjectOps({ a: 1, b: { c: 3 } }) | ||
); | ||
}); | ||
|
||
test('#transform errors out if path doesn\'t exist', () => { | ||
should(() => new ObjectOps({ a: 1, b: { c: 2 } }).transform('a.b', () => {})) | ||
.throw(TypeError, { message: 'Path is invalid at depth 0.' }); | ||
test('#transform errors out if path doesn\'t exist', t => { | ||
t.throws( | ||
() => new ObjectOps({ a: 1, b: { c: 2 } }).transform('a.b', () => {}), | ||
TypeError, | ||
'Path is invalid at depth 0.' | ||
); | ||
}); |
Oops, something went wrong.