diff --git a/lib/chai/utils/getPathInfo.js b/lib/chai/utils/getPathInfo.js index 538b2a1c9..67aa66198 100644 --- a/lib/chai/utils/getPathInfo.js +++ b/lib/chai/utils/getPathInfo.js @@ -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), }; diff --git a/test/expect.js b/test/expect.js index 9db12dee0..cd204a9b0 100644 --- a/test/expect.js +++ b/test/expect.js @@ -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]'");