Skip to content

Commit

Permalink
Merge pull request #489 from astorije/astorije/aliases
Browse files Browse the repository at this point in the history
Various work on aliases
  • Loading branch information
keithamus committed Jul 19, 2015
2 parents 0d5e87a + e5071ed commit 40cdaa3
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 140 deletions.
108 changes: 62 additions & 46 deletions lib/chai/interface/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,38 +64,40 @@ module.exports = function (chai, util) {
};

/**
* ### .ok(object, [message])
* ### .isOk(object, [message])
*
* Asserts that `object` is truthy.
*
* assert.ok('everything', 'everything is ok');
* assert.ok(false, 'this will fail');
* assert.isOk('everything', 'everything is ok');
* assert.isOk(false, 'this will fail');
*
* @name ok
* @name isOk
* @alias ok
* @param {Mixed} object to test
* @param {String} message
* @api public
*/

assert.ok = function (val, msg) {
assert.isOk = function (val, msg) {
new Assertion(val, msg).is.ok;
};

/**
* ### .notOk(object, [message])
* ### .isNotOk(object, [message])
*
* Asserts that `object` is falsy.
*
* assert.notOk('everything', 'this will fail');
* assert.notOk(false, 'this will pass');
* assert.isNotOk('everything', 'this will fail');
* assert.isNotOk(false, 'this will pass');
*
* @name notOk
* @name isNotOk
* @alias notOk
* @param {Mixed} object to test
* @param {String} message
* @api public
*/

assert.notOk = function (val, msg) {
assert.isNotOk = function (val, msg) {
new Assertion(val, msg).is.not.ok;
};

Expand Down Expand Up @@ -964,11 +966,11 @@ module.exports = function (chai, util) {
* `constructor`, or alternately that it will throw an error with message
* matching `regexp`.
*
* assert.throw(fn, 'function throws a reference error');
* assert.throw(fn, /function throws a reference error/);
* assert.throw(fn, ReferenceError);
* assert.throw(fn, ReferenceError, 'function throws a reference error');
* assert.throw(fn, ReferenceError, /function throws a reference error/);
* assert.throws(fn, 'function throws a reference error');
* assert.throws(fn, /function throws a reference error/);
* assert.throws(fn, ReferenceError);
* assert.throws(fn, ReferenceError, 'function throws a reference error');
* assert.throws(fn, ReferenceError, /function throws a reference error/);
*
* @name throws
* @alias throw
Expand All @@ -981,13 +983,13 @@ module.exports = function (chai, util) {
* @api public
*/

assert.Throw = function (fn, errt, errs, msg) {
assert.throws = function (fn, errt, errs, msg) {
if ('string' === typeof errt || errt instanceof RegExp) {
errs = errt;
errt = null;
}

var assertErr = new Assertion(fn, msg).to.Throw(errt, errs);
var assertErr = new Assertion(fn, msg).to.throw(errt, errs);
return flag(assertErr, 'object');
};

Expand Down Expand Up @@ -1277,7 +1279,7 @@ module.exports = function (chai, util) {
* ### .ifError(object)
*
* Asserts if value is not a false value, and throws if it is a true value.
* This is added to allow for chai to be a drop-in replacement for Node's
* This is added to allow for chai to be a drop-in replacement for Node's
* assert class.
*
* var err = new Error('I am a custom error');
Expand All @@ -1295,117 +1297,123 @@ module.exports = function (chai, util) {
};

/**
* ### .extensible(object)
* ### .isExtensible(object)
*
* Asserts that `object` is extensible (can have new properties added to it).
*
* assert.extensible({});
* assert.isExtensible({});
*
* @name extensible
* @name isExtensible
* @alias extensible
* @param {Object} object
* @param {String} message _optional_
* @api public
*/

assert.extensible = function (obj, msg) {
assert.isExtensible = function (obj, msg) {
new Assertion(obj, msg).to.be.extensible;
};

/**
* ### .notExtensible(object)
* ### .isNotExtensible(object)
*
* Asserts that `object` is _not_ extensible.
*
* var nonExtensibleObject = Object.preventExtensions({});
* var sealedObject = Object.seal({});
* var frozenObject = Object.freese({});
*
* assert.notExtensible(nonExtensibleObject);
* assert.notExtensible(sealedObject);
* assert.notExtensible(frozenObject);
* assert.isNotExtensible(nonExtensibleObject);
* assert.isNotExtensible(sealedObject);
* assert.isNotExtensible(frozenObject);
*
* @name notExtensible
* @name isNotExtensible
* @alias notExtensible
* @param {Object} object
* @param {String} message _optional_
* @api public
*/

assert.notExtensible = function (obj, msg) {
assert.isNotExtensible = function (obj, msg) {
new Assertion(obj, msg).to.not.be.extensible;
};

/**
* ### .sealed(object)
* ### .isSealed(object)
*
* Asserts that `object` is sealed (cannot have new properties added to it
* and its existing properties cannot be removed).
*
* var sealedObject = Object.seal({});
* var frozenObject = Object.seal({});
*
* assert.sealed(sealedObject);
* assert.sealed(frozenObject);
* assert.isSealed(sealedObject);
* assert.isSealed(frozenObject);
*
* @name sealed
* @name isSealed
* @alias sealed
* @param {Object} object
* @param {String} message _optional_
* @api public
*/

assert.sealed = function (obj, msg) {
assert.isSealed = function (obj, msg) {
new Assertion(obj, msg).to.be.sealed;
};

/**
* ### .notSealed(object)
* ### .isNotSealed(object)
*
* Asserts that `object` is _not_ sealed.
*
* assert.notSealed({});
* assert.isNotSealed({});
*
* @name notSealed
* @name isNotSealed
* @alias notSealed
* @param {Object} object
* @param {String} message _optional_
* @api public
*/

assert.notSealed = function (obj, msg) {
assert.isNotSealed = function (obj, msg) {
new Assertion(obj, msg).to.not.be.sealed;
};

/**
* ### .frozen(object)
* ### .isFrozen(object)
*
* Asserts that `object` is frozen (cannot have new properties added to it
* and its existing properties cannot be modified).
*
* var frozenObject = Object.freeze({});
* assert.frozen(frozenObject);
*
* @name frozen
* @name isFrozen
* @alias frozen
* @param {Object} object
* @param {String} message _optional_
* @api public
*/

assert.frozen = function (obj, msg) {
assert.isFrozen = function (obj, msg) {
new Assertion(obj, msg).to.be.frozen;
};

/**
* ### .notFrozen(object)
* ### .isNotFrozen(object)
*
* Asserts that `object` is _not_ frozen.
*
* assert.notFrozen({});
* assert.isNotFrozen({});
*
* @name notSealed
* @name isNotFrozen
* @alias notFrozen
* @param {Object} object
* @param {String} message _optional_
* @api public
*/

assert.notFrozen = function (obj, msg) {
assert.isNotFrozen = function (obj, msg) {
new Assertion(obj, msg).to.not.be.frozen;
};

Expand All @@ -1417,6 +1425,14 @@ module.exports = function (chai, util) {
assert[as] = assert[name];
return alias;
})
('Throw', 'throw')
('Throw', 'throws');
('isOk', 'ok')
('isNotOk', 'notOk')
('throws', 'throw')
('throws', 'Throw')
('isExtensible', 'extensible')
('isNotExtensible', 'notExtensible')
('isSealed', 'sealed')
('isNotSealed', 'notSealed')
('isFrozen', 'frozen')
('isNotFrozen', 'notFrozen');
};

0 comments on commit 40cdaa3

Please sign in to comment.