Skip to content

Commit 40cdaa3

Browse files
committed
Merge pull request #489 from astorije/astorije/aliases
Various work on aliases
2 parents 0d5e87a + e5071ed commit 40cdaa3

File tree

2 files changed

+173
-140
lines changed

2 files changed

+173
-140
lines changed

lib/chai/interface/assert.js

Lines changed: 62 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -64,38 +64,40 @@ module.exports = function (chai, util) {
6464
};
6565

6666
/**
67-
* ### .ok(object, [message])
67+
* ### .isOk(object, [message])
6868
*
6969
* Asserts that `object` is truthy.
7070
*
71-
* assert.ok('everything', 'everything is ok');
72-
* assert.ok(false, 'this will fail');
71+
* assert.isOk('everything', 'everything is ok');
72+
* assert.isOk(false, 'this will fail');
7373
*
74-
* @name ok
74+
* @name isOk
75+
* @alias ok
7576
* @param {Mixed} object to test
7677
* @param {String} message
7778
* @api public
7879
*/
7980

80-
assert.ok = function (val, msg) {
81+
assert.isOk = function (val, msg) {
8182
new Assertion(val, msg).is.ok;
8283
};
8384

8485
/**
85-
* ### .notOk(object, [message])
86+
* ### .isNotOk(object, [message])
8687
*
8788
* Asserts that `object` is falsy.
8889
*
89-
* assert.notOk('everything', 'this will fail');
90-
* assert.notOk(false, 'this will pass');
90+
* assert.isNotOk('everything', 'this will fail');
91+
* assert.isNotOk(false, 'this will pass');
9192
*
92-
* @name notOk
93+
* @name isNotOk
94+
* @alias notOk
9395
* @param {Mixed} object to test
9496
* @param {String} message
9597
* @api public
9698
*/
9799

98-
assert.notOk = function (val, msg) {
100+
assert.isNotOk = function (val, msg) {
99101
new Assertion(val, msg).is.not.ok;
100102
};
101103

@@ -964,11 +966,11 @@ module.exports = function (chai, util) {
964966
* `constructor`, or alternately that it will throw an error with message
965967
* matching `regexp`.
966968
*
967-
* assert.throw(fn, 'function throws a reference error');
968-
* assert.throw(fn, /function throws a reference error/);
969-
* assert.throw(fn, ReferenceError);
970-
* assert.throw(fn, ReferenceError, 'function throws a reference error');
971-
* assert.throw(fn, ReferenceError, /function throws a reference error/);
969+
* assert.throws(fn, 'function throws a reference error');
970+
* assert.throws(fn, /function throws a reference error/);
971+
* assert.throws(fn, ReferenceError);
972+
* assert.throws(fn, ReferenceError, 'function throws a reference error');
973+
* assert.throws(fn, ReferenceError, /function throws a reference error/);
972974
*
973975
* @name throws
974976
* @alias throw
@@ -981,13 +983,13 @@ module.exports = function (chai, util) {
981983
* @api public
982984
*/
983985

984-
assert.Throw = function (fn, errt, errs, msg) {
986+
assert.throws = function (fn, errt, errs, msg) {
985987
if ('string' === typeof errt || errt instanceof RegExp) {
986988
errs = errt;
987989
errt = null;
988990
}
989991

990-
var assertErr = new Assertion(fn, msg).to.Throw(errt, errs);
992+
var assertErr = new Assertion(fn, msg).to.throw(errt, errs);
991993
return flag(assertErr, 'object');
992994
};
993995

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

12971299
/**
1298-
* ### .extensible(object)
1300+
* ### .isExtensible(object)
12991301
*
13001302
* Asserts that `object` is extensible (can have new properties added to it).
13011303
*
1302-
* assert.extensible({});
1304+
* assert.isExtensible({});
13031305
*
1304-
* @name extensible
1306+
* @name isExtensible
1307+
* @alias extensible
13051308
* @param {Object} object
13061309
* @param {String} message _optional_
13071310
* @api public
13081311
*/
13091312

1310-
assert.extensible = function (obj, msg) {
1313+
assert.isExtensible = function (obj, msg) {
13111314
new Assertion(obj, msg).to.be.extensible;
13121315
};
13131316

13141317
/**
1315-
* ### .notExtensible(object)
1318+
* ### .isNotExtensible(object)
13161319
*
13171320
* Asserts that `object` is _not_ extensible.
13181321
*
13191322
* var nonExtensibleObject = Object.preventExtensions({});
13201323
* var sealedObject = Object.seal({});
13211324
* var frozenObject = Object.freese({});
13221325
*
1323-
* assert.notExtensible(nonExtensibleObject);
1324-
* assert.notExtensible(sealedObject);
1325-
* assert.notExtensible(frozenObject);
1326+
* assert.isNotExtensible(nonExtensibleObject);
1327+
* assert.isNotExtensible(sealedObject);
1328+
* assert.isNotExtensible(frozenObject);
13261329
*
1327-
* @name notExtensible
1330+
* @name isNotExtensible
1331+
* @alias notExtensible
13281332
* @param {Object} object
13291333
* @param {String} message _optional_
13301334
* @api public
13311335
*/
13321336

1333-
assert.notExtensible = function (obj, msg) {
1337+
assert.isNotExtensible = function (obj, msg) {
13341338
new Assertion(obj, msg).to.not.be.extensible;
13351339
};
13361340

13371341
/**
1338-
* ### .sealed(object)
1342+
* ### .isSealed(object)
13391343
*
13401344
* Asserts that `object` is sealed (cannot have new properties added to it
13411345
* and its existing properties cannot be removed).
13421346
*
13431347
* var sealedObject = Object.seal({});
13441348
* var frozenObject = Object.seal({});
13451349
*
1346-
* assert.sealed(sealedObject);
1347-
* assert.sealed(frozenObject);
1350+
* assert.isSealed(sealedObject);
1351+
* assert.isSealed(frozenObject);
13481352
*
1349-
* @name sealed
1353+
* @name isSealed
1354+
* @alias sealed
13501355
* @param {Object} object
13511356
* @param {String} message _optional_
13521357
* @api public
13531358
*/
13541359

1355-
assert.sealed = function (obj, msg) {
1360+
assert.isSealed = function (obj, msg) {
13561361
new Assertion(obj, msg).to.be.sealed;
13571362
};
13581363

13591364
/**
1360-
* ### .notSealed(object)
1365+
* ### .isNotSealed(object)
13611366
*
13621367
* Asserts that `object` is _not_ sealed.
13631368
*
1364-
* assert.notSealed({});
1369+
* assert.isNotSealed({});
13651370
*
1366-
* @name notSealed
1371+
* @name isNotSealed
1372+
* @alias notSealed
13671373
* @param {Object} object
13681374
* @param {String} message _optional_
13691375
* @api public
13701376
*/
13711377

1372-
assert.notSealed = function (obj, msg) {
1378+
assert.isNotSealed = function (obj, msg) {
13731379
new Assertion(obj, msg).to.not.be.sealed;
13741380
};
13751381

13761382
/**
1377-
* ### .frozen(object)
1383+
* ### .isFrozen(object)
13781384
*
13791385
* Asserts that `object` is frozen (cannot have new properties added to it
13801386
* and its existing properties cannot be modified).
13811387
*
13821388
* var frozenObject = Object.freeze({});
13831389
* assert.frozen(frozenObject);
13841390
*
1385-
* @name frozen
1391+
* @name isFrozen
1392+
* @alias frozen
13861393
* @param {Object} object
13871394
* @param {String} message _optional_
13881395
* @api public
13891396
*/
13901397

1391-
assert.frozen = function (obj, msg) {
1398+
assert.isFrozen = function (obj, msg) {
13921399
new Assertion(obj, msg).to.be.frozen;
13931400
};
13941401

13951402
/**
1396-
* ### .notFrozen(object)
1403+
* ### .isNotFrozen(object)
13971404
*
13981405
* Asserts that `object` is _not_ frozen.
13991406
*
1400-
* assert.notFrozen({});
1407+
* assert.isNotFrozen({});
14011408
*
1402-
* @name notSealed
1409+
* @name isNotFrozen
1410+
* @alias notFrozen
14031411
* @param {Object} object
14041412
* @param {String} message _optional_
14051413
* @api public
14061414
*/
14071415

1408-
assert.notFrozen = function (obj, msg) {
1416+
assert.isNotFrozen = function (obj, msg) {
14091417
new Assertion(obj, msg).to.not.be.frozen;
14101418
};
14111419

@@ -1417,6 +1425,14 @@ module.exports = function (chai, util) {
14171425
assert[as] = assert[name];
14181426
return alias;
14191427
})
1420-
('Throw', 'throw')
1421-
('Throw', 'throws');
1428+
('isOk', 'ok')
1429+
('isNotOk', 'notOk')
1430+
('throws', 'throw')
1431+
('throws', 'Throw')
1432+
('isExtensible', 'extensible')
1433+
('isNotExtensible', 'notExtensible')
1434+
('isSealed', 'sealed')
1435+
('isNotSealed', 'notSealed')
1436+
('isFrozen', 'frozen')
1437+
('isNotFrozen', 'notFrozen');
14221438
};

0 commit comments

Comments
 (0)