Skip to content

Loading…

expect({ a: undefined }).to.have.property('a') now passes. #7

Merged
merged 1 commit into from

2 participants

@vlazzle

More consistent with previous behavior, since before
expect({ a: undefined }).to.have.own.property('a') passed but
expect({ a: undefined }).to.have.property('a') failed

Also less surprising in general since before
expect( 'a' in { a: undefined } ).to.be.ok() passed but
expect({ a: undefined }).to.have.property('a') failed

@vlazzle vlazzle expect({ a: undefined }).to.have.property('a') now passes.
More consistent with previous behavior, since before
expect({ a: undefined }).to.have.own.property('a') passed but
expect({ a: undefined }).to.have.property('a') failed

Also less surprising in general since before
expect( 'a' in { a: undefined } ).to.be.ok() passed but
expect({ a: undefined }).to.have.property('a') failed
2c8f4c5
@vlazzle

bump :)

@rauchg rauchg merged commit 0b856ac into Automattic:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 17, 2012
  1. @vlazzle

    expect({ a: undefined }).to.have.property('a') now passes.

    vlazzle committed
    More consistent with previous behavior, since before
    expect({ a: undefined }).to.have.own.property('a') passed but
    expect({ a: undefined }).to.have.property('a') failed
    
    Also less surprising in general since before
    expect( 'a' in { a: undefined } ).to.be.ok() passed but
    expect({ a: undefined }).to.have.property('a') failed
This page is out of date. Refresh to see the latest.
Showing with 18 additions and 1 deletion.
  1. +8 −1 expect.js
  2. +10 −0 test/expect.js
View
9 expect.js
@@ -310,8 +310,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
@@ -283,14 +283,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);
@@ -303,6 +309,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 () {
Something went wrong with that request. Please try again.