mirror of
https://github.com/chaijs/chai
synced 2024-11-14 15:57:10 +00:00
Merge pull request #992 from meeber/property-target-type
fix: check target's type in `.property` assertion
This commit is contained in:
commit
351e9689d3
3 changed files with 26 additions and 1 deletions
|
@ -1644,6 +1644,7 @@ module.exports = function (chai, _) {
|
|||
var isNested = flag(this, 'nested')
|
||||
, isOwn = flag(this, 'own')
|
||||
, flagMsg = flag(this, 'message')
|
||||
, obj = flag(this, 'object')
|
||||
, ssfi = flag(this, 'ssfi');
|
||||
|
||||
if (isNested && isOwn) {
|
||||
|
@ -1655,9 +1656,17 @@ module.exports = function (chai, _) {
|
|||
);
|
||||
}
|
||||
|
||||
if (obj === null || obj === undefined) {
|
||||
flagMsg = flagMsg ? flagMsg + ': ' : '';
|
||||
throw new AssertionError(
|
||||
flagMsg + 'Target cannot be null or undefined.',
|
||||
undefined,
|
||||
ssfi
|
||||
);
|
||||
}
|
||||
|
||||
var isDeep = flag(this, 'deep')
|
||||
, negate = flag(this, 'negate')
|
||||
, obj = flag(this, 'object')
|
||||
, pathInfo = isNested ? _.getPathInfo(obj, name) : null
|
||||
, value = isNested ? pathInfo.value : obj[name];
|
||||
|
||||
|
|
|
@ -1339,6 +1339,14 @@ describe('assert', function () {
|
|||
err(function () {
|
||||
assert.notNestedPropertyVal(obj, 'foo.bar', 'baz', 'blah');
|
||||
}, "blah: expected { foo: { bar: 'baz' } } to not have nested property 'foo.bar' of 'baz'");
|
||||
|
||||
err(function () {
|
||||
assert.property(null, 'a', 'blah');
|
||||
}, "blah: Target cannot be null or undefined.");
|
||||
|
||||
err(function () {
|
||||
assert.property(undefined, 'a', 'blah');
|
||||
}, "blah: Target cannot be null or undefined.");
|
||||
});
|
||||
|
||||
it('deepPropertyVal', function () {
|
||||
|
|
|
@ -1263,6 +1263,14 @@ describe('expect', function () {
|
|||
err(function() {
|
||||
expect({a: {b: 1}}, 'blah').to.have.own.nested.property("a.b");
|
||||
}, "blah: The \"nested\" and \"own\" flags cannot be combined.");
|
||||
|
||||
err(function () {
|
||||
expect(null, 'blah').to.have.property("a");
|
||||
}, "blah: Target cannot be null or undefined.");
|
||||
|
||||
err(function () {
|
||||
expect(undefined, 'blah').to.have.property("a");
|
||||
}, "blah: Target cannot be null or undefined.");
|
||||
});
|
||||
|
||||
it('property(name, val)', function(){
|
||||
|
|
Loading…
Reference in a new issue