New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertions to test if objects are extensible. #479

Merged
merged 3 commits into from Jul 12, 2015

Conversation

Projects
None yet
2 participants
@matthewlucock
Contributor

matthewlucock commented Jul 12, 2015

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

This comment has been minimized.

Show comment
Hide comment
@keithamus

keithamus Jul 12, 2015

Member

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

Member

keithamus commented Jul 12, 2015

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

keithamus added a commit that referenced this pull request Jul 12, 2015

Merge pull request #479 from matthewlucock/extensible-assertions
Assertions to test if objects are extensible.

@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 matthewlucock:extensible-assertions branch Jul 13, 2015

@matthewlucock matthewlucock restored the matthewlucock:extensible-assertions branch Jul 13, 2015

@renovate renovate bot referenced this pull request Feb 2, 2018

Open

Update dependency chai to v4 #30

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