-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
244 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,138 @@ | ||
var dotProp = require('..'); | ||
|
||
describe('dot-prop-immutable.merge.spec.js', function () { | ||
|
||
var obj = { | ||
a: 1, | ||
b: { | ||
x: 1, | ||
y: 2 | ||
}, | ||
c: [1, 2], | ||
d: null, | ||
'b.x': 10 | ||
}; | ||
|
||
var arr = [1, {a: [1, 2]}]; | ||
|
||
var result; | ||
describe('when have an object', () => { | ||
|
||
describe('merge an object value into object', () => { | ||
|
||
before(function () { | ||
result = dotProp.merge(obj, 'b', {z: 3}); | ||
}); | ||
|
||
it('should merge prop', () => { | ||
expect(result).to.eql({ | ||
a: 1, | ||
b: { | ||
x: 1, | ||
y: 2, | ||
z: 3 | ||
}, | ||
c: [1, 2], | ||
d: null, | ||
'b.x': 10 | ||
}); | ||
}); | ||
|
||
it('invariant', objInvariant); | ||
|
||
}); | ||
|
||
describe('merge an array value into array', () => { | ||
|
||
before(function () { | ||
result = dotProp.merge(obj, 'c', [3, 4]); | ||
}); | ||
|
||
it('should merge prop', () => { | ||
expect(result).to.eql({ | ||
a: 1, | ||
b: { | ||
x: 1, | ||
y: 2 | ||
}, | ||
c: [1, 2, 3, 4], | ||
d: null, | ||
'b.x': 10 | ||
}); | ||
}); | ||
|
||
it('invariant', objInvariant); | ||
|
||
}); | ||
|
||
describe('merge an object value into null', () => { | ||
|
||
before(function () { | ||
result = dotProp.merge(obj, 'd', {foo: 'bar'}); | ||
}); | ||
|
||
it('should merge prop', () => { | ||
expect(result).to.eql({ | ||
a: 1, | ||
b: { | ||
x: 1, | ||
y: 2 | ||
}, | ||
c: [1, 2], | ||
d: {foo: 'bar'}, | ||
'b.x': 10 | ||
}); | ||
}); | ||
|
||
it('invariant', objInvariant); | ||
|
||
}); | ||
|
||
describe('merge an object value into undefined', () => { | ||
|
||
before(function () { | ||
result = dotProp.merge(obj, 'z', {foo: 'bar'}); | ||
}); | ||
|
||
it('should merge prop', () => { | ||
expect(result).to.eql({ | ||
a: 1, | ||
b: { | ||
x: 1, | ||
y: 2 | ||
}, | ||
c: [1, 2], | ||
d: null, | ||
z: {foo: 'bar'}, | ||
'b.x': 10 | ||
}); | ||
}); | ||
|
||
it('invariant', objInvariant); | ||
|
||
}); | ||
|
||
|
||
}); | ||
|
||
function objInvariant() { | ||
expect(obj).to.eql({ | ||
a: 1, | ||
b: { | ||
x: 1, | ||
y: 2 | ||
}, | ||
c: [1, 2], | ||
d: null, | ||
'b.x': 10 | ||
}); | ||
} | ||
|
||
function arrInvariant() { | ||
expect(arr).to.eql( | ||
[1, {a: [1, 2]}] | ||
); | ||
} | ||
}); | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
var dotProp = require('..'); | ||
|
||
describe('dot-prop-immutable.toggle.spec.js', function () { | ||
|
||
var arr = [1, {a: false}]; | ||
|
||
var result; | ||
describe('when have an array', () => { | ||
|
||
describe('toggle a value', () => { | ||
|
||
before(function () { | ||
result = dotProp.toggle(arr, '1.a'); | ||
}); | ||
|
||
|
||
it('should toggle prop', () => { | ||
expect(result).to.eql( | ||
[1, {a: true}]); | ||
}); | ||
|
||
it('invariant', arrInvariant); | ||
}); | ||
}); | ||
|
||
function arrInvariant() { | ||
expect(arr).to.eql( | ||
[1, {a: false}] | ||
); | ||
} | ||
}); | ||
|
||
|