Skip to content

Commit

Permalink
Merge pull request #385 from eldritch-fossicker/master
Browse files Browse the repository at this point in the history
fix indexing into array with deep propery
  • Loading branch information
keithamus committed Mar 3, 2015
2 parents 062d731 + bb8d0bf commit dbeb2a8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/chai/utils/getPathInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = function getPathInfo(path, obj) {
last = parsed[parsed.length - 1];

var info = {
parent: _getPathValue(parsed, obj, parsed.length - 1),
parent: parsed.length > 1 ? _getPathValue(parsed, obj, parsed.length - 1) : obj,
name: last.p || last.i,
value: _getPathValue(parsed, obj),
};
Expand Down
6 changes: 6 additions & 0 deletions test/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,12 @@ describe('expect', function () {
expect(deepObj).to.have.deep.property('green.tea', 'matcha');
expect(deepObj).to.have.deep.property('teas[1]', 'matcha');
expect(deepObj).to.have.deep.property('teas[2].tea', 'konacha');

expect(deepObj).to.have.property('teas')
.that.is.an('array')
.with.deep.property('[2]')
.that.deep.equals({tea: 'konacha'});

err(function(){
expect(deepObj).to.have.deep.property('teas[3]');
}, "expected { Object (green, teas) } to have a deep property 'teas[3]'");
Expand Down

0 comments on commit dbeb2a8

Please sign in to comment.