Assertions to test if objects are extensible. #479

Merged
merged 3 commits into from Jul 12, 2015

Projects

None yet

2 participants

@matthewlucock
Contributor

Thin assertions to test if objects are extensible, sealed, or frozen with Object.isExtensible(), Object.isSealed(), and Object.isFrozen(). Closes #478.

var nonExtensibleObject = Object.preventExtensions({});
var sealedObject = Object.seal({});
var frozenObject = Object.freeze({});

/**
 * Extensible
 */

assert.extensible({});
assert.notExtensible(nonExtensibleObject);
assert.notExtensible(sealedObject);
assert.notExtensible(frozenObject);

expect({}).to.be.extensible;
expect(nonExtensibleObject).to.not.be.extensible;
expect(sealedObject).to.not.be.extensible;
expect(frozenObject).to.not.be.extensible;

({}).should.be.extensible
nonExtensibleObject.should.not.be.extensible;
sealedObject.should.not.be.extensible;
frozenObject.should.not.be.extensible;

/**
 * Sealed
 */

assert.sealed(sealedObject);
assert.sealed(frozenObject);
assert.notSealed({});

expect(sealedObject).to.be.sealed;
expect(frozenObject).to.be.sealed;
expect({}).to.not.be.sealed;

sealedObject.should.be.sealed;
frozenObject.should.be.sealed;
({}).should.not.be.sealed;

/**
 * Frozen
 */

assert.frozen(frozenObject);
assert.notFrozen({});

expect(frozenObject).to.be.frozen;
expect({}).to.not.be.frozen;

frozenObject.should.be.frozen;
({}).should.not.be.frozen;

(I did my best to adhere to the already-established code and test style, but if there's something I didn't get quite right or something I could make better, let me know.)

@keithamus
Member

Awesome work @matthewlucock! Great example of a thorough PR, good explanation, good code, good tests. Perfect 😍

@keithamus keithamus merged commit 95a172b into chaijs:master Jul 12, 2015

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@matthewlucock matthewlucock deleted the unknown repository branch Jul 13, 2015
@matthewlucock matthewlucock restored the unknown repository branch Jul 13, 2015
@marekventur marekventur referenced this pull request in Gamevy/pixi-packer Dec 14, 2015
Merged

Update "chai" to version ^3.4.1 #15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment