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
1 parent
1407381
commit 5e88625
Showing
3 changed files
with
84 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
describe('.get(obj, path)', function () { | ||
it('should get the value for simple nested object', function () { | ||
var obj = { hello: { universe: 'world' }} | ||
, val = properties.get(obj, 'hello.universe'); | ||
val.should.equal('world'); | ||
}); | ||
|
||
it('should get the value for simple array', function () { | ||
var obj = { hello: [ 'zero', 'one' ] } | ||
, val = properties.get(obj, 'hello[1]'); | ||
val.should.equal('one'); | ||
}); | ||
|
||
it('should get the value of nested array', function () { | ||
var obj = { hello: [ 'zero', [ 'a', 'b' ] ] } | ||
, val = properties.get(obj, 'hello[1][0]'); | ||
val.should.equal('a'); | ||
}); | ||
|
||
it('should get the value of array only', function () { | ||
var obj = [ 'zero', 'one' ] | ||
, val = properties.get(obj, '[1]'); | ||
val.should.equal('one'); | ||
}); | ||
|
||
it('should get the value of array only nested', function () { | ||
var obj = [ 'zero', [ 'a', 'b' ] ] | ||
, val = properties.get(obj, '[1][1]'); | ||
val.should.equal('b'); | ||
}); | ||
}); |
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,51 @@ | ||
describe('.set(obj, path, value)', function () { | ||
it('should allow value to be set in simple object', function () { | ||
var obj = {}; | ||
properties.set(obj, 'hello', 'universe'); | ||
obj.should.deep.equal({ hello: 'universe' }); | ||
}); | ||
|
||
it('should allow nested object value to be set', function () { | ||
var obj = {}; | ||
properties.set(obj, 'hello.universe', 'properties'); | ||
obj.should.deep.equal({ hello: { universe: 'properties' }}); | ||
}); | ||
|
||
it('should allow nested array value to be set', function () { | ||
var obj = {}; | ||
properties.set(obj, 'hello.universe[1].properties', 'galaxy'); | ||
obj.should.deep.equal({ hello: { universe: [ , { properties: 'galaxy' } ] }}); | ||
}); | ||
|
||
it('should allow value to be REset in simple object', function () { | ||
var obj = { hello: 'world' }; | ||
properties.set(obj, 'hello', 'universe'); | ||
obj.should.deep.equal({ hello: 'universe' }); | ||
}); | ||
|
||
it('should allow value to be set in complex object', function () { | ||
var obj = { hello: { }}; | ||
properties.set(obj, 'hello.universe', 42); | ||
obj.should.deep.equal({ hello: { universe: 42 }}); | ||
}); | ||
|
||
it('should allow value to be REset in complex object', function () { | ||
var obj = { hello: { universe: 100 }}; | ||
properties.set(obj, 'hello.universe', 42); | ||
obj.should.deep.equal({ hello: { universe: 42 }}); | ||
}); | ||
|
||
it('should allow for value to be set in array', function () { | ||
var obj = { hello: [] }; | ||
properties.set(obj, 'hello[0]', 1); | ||
obj.should.deep.equal({ hello: [1] }); | ||
properties.set(obj, 'hello[2]', 3); | ||
obj.should.deep.equal({ hello: [1 , , 3] }); | ||
}); | ||
|
||
it('should allow for value to be REset in array', function () { | ||
var obj = { hello: [ 1, 2, 4 ] }; | ||
properties.set(obj, 'hello[2]', 3); | ||
obj.should.deep.equal({ hello: [ 1, 2, 3 ] }); | ||
}); | ||
}); |