Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #7 from vovik/master

expect({ a: undefined }).to.have.property('a') now passes.
  • Loading branch information...
commit 0b856ac4d33f08f7b2b8efe9e3ec2061a38ac7e5 2 parents d1a9689 + 2c8f4c5
@rauchg rauchg authored
Showing with 18 additions and 1 deletion.
  1. +8 −1 expect.js
  2. +10 −0 test/expect.js
View
9 expect.js
@@ -332,8 +332,15 @@
throw new Error(i(this.obj) + ' has no property ' + i(name));
}
} else {
+ var hasProp;
+ try {
+ hasProp = name in this.obj
+ } catch (e) {
+ hasProp = undefined !== this.obj[name]
+ }
+
this.assert(
- undefined !== this.obj[name]
+ hasProp
, 'expected ' + i(this.obj) + ' to have a property ' + i(name)
, 'expected ' + i(this.obj) + ' to not have a property ' + i(name));
}
View
10 test/expect.js
@@ -308,14 +308,20 @@ describe('expect', function () {
it('should test property(name)', function () {
expect('test').to.have.property('length');
expect(4).to.not.have.property('length');
+ expect({ length: undefined }).to.have.property('length');
err(function () {
expect('asd').to.have.property('foo');
}, "expected 'asd' to have a property 'foo'");
+
+ err(function () {
+ expect({ length: undefined }).to.not.have.property('length');
+ }, "expected { length: undefined } to not have a property 'length'");
});
it('should test property(name, val)', function () {
expect('test').to.have.property('length', 4);
+ expect({ length: undefined }).to.have.property('length', undefined);
err(function () {
expect('asd').to.have.property('length', 4);
@@ -328,6 +334,10 @@ describe('expect', function () {
err(function () {
expect('asd').to.not.have.property('foo', 3);
}, "'asd' has no property 'foo'");
+
+ err(function () {
+ expect({ length: undefined }).to.not.have.property('length', undefined);
+ }, "expected { length: undefined } to not have a property 'length'");
});
it('should test own.property(name)', function () {
Please sign in to comment.
Something went wrong with that request. Please try again.