chai 2.2.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -64,38 +64,40 @@ module.exports = function (chai, util) {
64
64
  };
65
65
 
66
66
  /**
67
- * ### .ok(object, [message])
67
+ * ### .isOk(object, [message])
68
68
  *
69
69
  * Asserts that `object` is truthy.
70
70
  *
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');
73
73
  *
74
- * @name ok
74
+ * @name isOk
75
+ * @alias ok
75
76
  * @param {Mixed} object to test
76
77
  * @param {String} message
77
78
  * @api public
78
79
  */
79
80
 
80
- assert.ok = function (val, msg) {
81
+ assert.isOk = function (val, msg) {
81
82
  new Assertion(val, msg).is.ok;
82
83
  };
83
84
 
84
85
  /**
85
- * ### .notOk(object, [message])
86
+ * ### .isNotOk(object, [message])
86
87
  *
87
88
  * Asserts that `object` is falsy.
88
89
  *
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');
91
92
  *
92
- * @name notOk
93
+ * @name isNotOk
94
+ * @alias notOk
93
95
  * @param {Mixed} object to test
94
96
  * @param {String} message
95
97
  * @api public
96
98
  */
97
99
 
98
- assert.notOk = function (val, msg) {
100
+ assert.isNotOk = function (val, msg) {
99
101
  new Assertion(val, msg).is.not.ok;
100
102
  };
101
103
 
@@ -330,6 +332,37 @@ module.exports = function (chai, util) {
330
332
  new Assertion(val, msg).to.not.equal(null);
331
333
  };
332
334
 
335
+ /**
336
+ * ### .isNaN
337
+ * Asserts that value is NaN
338
+ *
339
+ * assert.isNaN('foo', 'foo is NaN');
340
+ *
341
+ * @name isNaN
342
+ * @param {Mixed} value
343
+ * @param {String} message
344
+ * @api public
345
+ */
346
+
347
+ assert.isNaN = function (val, msg) {
348
+ new Assertion(val, msg).to.be.NaN;
349
+ };
350
+
351
+ /**
352
+ * ### .isNotNaN
353
+ * Asserts that value is not NaN
354
+ *
355
+ * assert.isNotNaN(4, '4 is not NaN');
356
+ *
357
+ * @name isNotNaN
358
+ * @param {Mixed} value
359
+ * @param {String} message
360
+ * @api public
361
+ */
362
+ assert.isNotNaN = function (val, msg) {
363
+ new Assertion(val, msg).not.to.be.NaN;
364
+ };
365
+
333
366
  /**
334
367
  * ### .isUndefined(value, [message])
335
368
  *
@@ -700,7 +733,7 @@ module.exports = function (chai, util) {
700
733
  *
701
734
  * Asserts that `haystack` does not include `needle`. Works
702
735
  * for strings and arrays.
703
- *i
736
+ *
704
737
  * assert.notInclude('foobar', 'baz', 'string not include substring');
705
738
  * assert.notInclude([ 1, 2, 3 ], 4, 'array not include contain value');
706
739
  *
@@ -933,11 +966,11 @@ module.exports = function (chai, util) {
933
966
  * `constructor`, or alternately that it will throw an error with message
934
967
  * matching `regexp`.
935
968
  *
936
- * assert.throw(fn, 'function throws a reference error');
937
- * assert.throw(fn, /function throws a reference error/);
938
- * assert.throw(fn, ReferenceError);
939
- * assert.throw(fn, ReferenceError, 'function throws a reference error');
940
- * 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/);
941
974
  *
942
975
  * @name throws
943
976
  * @alias throw
@@ -950,13 +983,13 @@ module.exports = function (chai, util) {
950
983
  * @api public
951
984
  */
952
985
 
953
- assert.Throw = function (fn, errt, errs, msg) {
986
+ assert.throws = function (fn, errt, errs, msg) {
954
987
  if ('string' === typeof errt || errt instanceof RegExp) {
955
988
  errs = errt;
956
989
  errt = null;
957
990
  }
958
991
 
959
- var assertErr = new Assertion(fn, msg).to.Throw(errt, errs);
992
+ var assertErr = new Assertion(fn, msg).to.throw(errt, errs);
960
993
  return flag(assertErr, 'object');
961
994
  };
962
995
 
@@ -1243,11 +1276,145 @@ module.exports = function (chai, util) {
1243
1276
  }
1244
1277
 
1245
1278
  /*!
1246
- * Undocumented / untested
1279
+ * ### .ifError(object)
1280
+ *
1281
+ * Asserts if value is not a false value, and throws if it is a true value.
1282
+ * This is added to allow for chai to be a drop-in replacement for Node's
1283
+ * assert class.
1284
+ *
1285
+ * var err = new Error('I am a custom error');
1286
+ * assert.ifError(err); // Rethrows err!
1287
+ *
1288
+ * @name ifError
1289
+ * @param {Object} object
1290
+ * @api public
1291
+ */
1292
+
1293
+ assert.ifError = function (val) {
1294
+ if (val) {
1295
+ throw(val);
1296
+ }
1297
+ };
1298
+
1299
+ /**
1300
+ * ### .isExtensible(object)
1301
+ *
1302
+ * Asserts that `object` is extensible (can have new properties added to it).
1303
+ *
1304
+ * assert.isExtensible({});
1305
+ *
1306
+ * @name isExtensible
1307
+ * @alias extensible
1308
+ * @param {Object} object
1309
+ * @param {String} message _optional_
1310
+ * @api public
1311
+ */
1312
+
1313
+ assert.isExtensible = function (obj, msg) {
1314
+ new Assertion(obj, msg).to.be.extensible;
1315
+ };
1316
+
1317
+ /**
1318
+ * ### .isNotExtensible(object)
1319
+ *
1320
+ * Asserts that `object` is _not_ extensible.
1321
+ *
1322
+ * var nonExtensibleObject = Object.preventExtensions({});
1323
+ * var sealedObject = Object.seal({});
1324
+ * var frozenObject = Object.freese({});
1325
+ *
1326
+ * assert.isNotExtensible(nonExtensibleObject);
1327
+ * assert.isNotExtensible(sealedObject);
1328
+ * assert.isNotExtensible(frozenObject);
1329
+ *
1330
+ * @name isNotExtensible
1331
+ * @alias notExtensible
1332
+ * @param {Object} object
1333
+ * @param {String} message _optional_
1334
+ * @api public
1335
+ */
1336
+
1337
+ assert.isNotExtensible = function (obj, msg) {
1338
+ new Assertion(obj, msg).to.not.be.extensible;
1339
+ };
1340
+
1341
+ /**
1342
+ * ### .isSealed(object)
1343
+ *
1344
+ * Asserts that `object` is sealed (cannot have new properties added to it
1345
+ * and its existing properties cannot be removed).
1346
+ *
1347
+ * var sealedObject = Object.seal({});
1348
+ * var frozenObject = Object.seal({});
1349
+ *
1350
+ * assert.isSealed(sealedObject);
1351
+ * assert.isSealed(frozenObject);
1352
+ *
1353
+ * @name isSealed
1354
+ * @alias sealed
1355
+ * @param {Object} object
1356
+ * @param {String} message _optional_
1357
+ * @api public
1358
+ */
1359
+
1360
+ assert.isSealed = function (obj, msg) {
1361
+ new Assertion(obj, msg).to.be.sealed;
1362
+ };
1363
+
1364
+ /**
1365
+ * ### .isNotSealed(object)
1366
+ *
1367
+ * Asserts that `object` is _not_ sealed.
1368
+ *
1369
+ * assert.isNotSealed({});
1370
+ *
1371
+ * @name isNotSealed
1372
+ * @alias notSealed
1373
+ * @param {Object} object
1374
+ * @param {String} message _optional_
1375
+ * @api public
1376
+ */
1377
+
1378
+ assert.isNotSealed = function (obj, msg) {
1379
+ new Assertion(obj, msg).to.not.be.sealed;
1380
+ };
1381
+
1382
+ /**
1383
+ * ### .isFrozen(object)
1384
+ *
1385
+ * Asserts that `object` is frozen (cannot have new properties added to it
1386
+ * and its existing properties cannot be modified).
1387
+ *
1388
+ * var frozenObject = Object.freeze({});
1389
+ * assert.frozen(frozenObject);
1390
+ *
1391
+ * @name isFrozen
1392
+ * @alias frozen
1393
+ * @param {Object} object
1394
+ * @param {String} message _optional_
1395
+ * @api public
1396
+ */
1397
+
1398
+ assert.isFrozen = function (obj, msg) {
1399
+ new Assertion(obj, msg).to.be.frozen;
1400
+ };
1401
+
1402
+ /**
1403
+ * ### .isNotFrozen(object)
1404
+ *
1405
+ * Asserts that `object` is _not_ frozen.
1406
+ *
1407
+ * assert.isNotFrozen({});
1408
+ *
1409
+ * @name isNotFrozen
1410
+ * @alias notFrozen
1411
+ * @param {Object} object
1412
+ * @param {String} message _optional_
1413
+ * @api public
1247
1414
  */
1248
1415
 
1249
- assert.ifError = function (val, msg) {
1250
- new Assertion(val, msg).to.not.be.ok;
1416
+ assert.isNotFrozen = function (obj, msg) {
1417
+ new Assertion(obj, msg).to.not.be.frozen;
1251
1418
  };
1252
1419
 
1253
1420
  /*!
@@ -1258,6 +1425,14 @@ module.exports = function (chai, util) {
1258
1425
  assert[as] = assert[name];
1259
1426
  return alias;
1260
1427
  })
1261
- ('Throw', 'throw')
1262
- ('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');
1263
1438
  };
@@ -34,7 +34,7 @@ module.exports = function getPathInfo(path, obj) {
34
34
  var info = {
35
35
  parent: parsed.length > 1 ? _getPathValue(parsed, obj, parsed.length - 1) : obj,
36
36
  name: last.p || last.i,
37
- value: _getPathValue(parsed, obj),
37
+ value: _getPathValue(parsed, obj)
38
38
  };
39
39
  info.exists = hasProperty(info.name, info.parent);
40
40
 
@@ -17,7 +17,7 @@
17
17
  */
18
18
 
19
19
  module.exports = function getProperties(object) {
20
- var result = Object.getOwnPropertyNames(subject);
20
+ var result = Object.getOwnPropertyNames(object);
21
21
 
22
22
  function addProperty(property) {
23
23
  if (result.indexOf(property) === -1) {
@@ -25,7 +25,7 @@ module.exports = function getProperties(object) {
25
25
  }
26
26
  }
27
27
 
28
- var proto = Object.getPrototypeOf(subject);
28
+ var proto = Object.getPrototypeOf(object);
29
29
  while (proto !== null) {
30
30
  Object.getOwnPropertyNames(proto).forEach(addProperty);
31
31
  proto = Object.getPrototypeOf(proto);
@@ -4,7 +4,7 @@
4
4
  * MIT Licensed
5
5
  */
6
6
 
7
- var type = require('./type');
7
+ var type = require('type-detect');
8
8
 
9
9
  /**
10
10
  * ### .hasProperty(object, name)
@@ -20,7 +20,7 @@ exports.test = require('./test');
20
20
  * type utility
21
21
  */
22
22
 
23
- exports.type = require('./type');
23
+ exports.type = require('type-detect');
24
24
 
25
25
  /*!
26
26
  * message utility
package/lib/chai.js CHANGED
@@ -11,7 +11,7 @@ var used = []
11
11
  * Chai version
12
12
  */
13
13
 
14
- exports.version = '2.2.0';
14
+ exports.version = '3.2.0';
15
15
 
16
16
  /*!
17
17
  * Assertion Error
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "Veselin Todorov <hi@vesln.com>",
18
18
  "John Firebaugh <john.firebaugh@gmail.com>"
19
19
  ],
20
- "version": "2.2.0",
20
+ "version": "3.2.0",
21
21
  "repository": {
22
22
  "type": "git",
23
23
  "url": "https://github.com/chaijs/chai"
@@ -33,16 +33,19 @@
33
33
  "node": ">= 0.4.0"
34
34
  },
35
35
  "dependencies": {
36
- "assertion-error": "1.0.0",
37
- "deep-eql": "0.1.3"
36
+ "assertion-error": "^1.0.1",
37
+ "deep-eql": "^0.1.3",
38
+ "type-detect": "^1.0.0"
38
39
  },
39
40
  "devDependencies": {
40
- "component": "*",
41
- "karma": "0.12.x",
42
- "karma-mocha": "*",
43
- "karma-sauce-launcher": "0.2.x",
44
- "karma-phantomjs-launcher": "0.1.1",
45
- "mocha": "1.21.x",
46
- "istanbul": "0.2.x"
41
+ "browserify": "^10.2.1",
42
+ "bump-cli": "^1.1.3",
43
+ "karma": "^0.12.0",
44
+ "karma-mocha": "^0.1.10",
45
+ "karma-sauce-launcher": "^0.2.11",
46
+ "karma-phantomjs-launcher": "^0.2.0",
47
+ "karma-firefox-launcher": "^0.1.6",
48
+ "mocha": "^2.2.5",
49
+ "istanbul": "^0.3.14"
47
50
  }
48
51
  }
@@ -1,45 +0,0 @@
1
- /*!
2
- * Chai - type utility
3
- * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
4
- * MIT Licensed
5
- */
6
-
7
- /*!
8
- * Detectable javascript natives
9
- */
10
-
11
- var natives = {
12
- '[object Arguments]': 'arguments'
13
- , '[object Array]': 'array'
14
- , '[object Date]': 'date'
15
- , '[object Function]': 'function'
16
- , '[object Number]': 'number'
17
- , '[object RegExp]': 'regexp'
18
- , '[object String]': 'string'
19
- };
20
-
21
- /**
22
- * ### type(object)
23
- *
24
- * Better implementation of `typeof` detection that can
25
- * be used cross-browser. Handles the inconsistencies of
26
- * Array, `null`, and `undefined` detection.
27
- *
28
- * utils.type({}) // 'object'
29
- * utils.type(null) // `null'
30
- * utils.type(undefined) // `undefined`
31
- * utils.type([]) // `array`
32
- *
33
- * @param {Mixed} object to detect type of
34
- * @name type
35
- * @api private
36
- */
37
-
38
- module.exports = function (obj) {
39
- var str = Object.prototype.toString.call(obj);
40
- if (natives[str]) return natives[str];
41
- if (obj === null) return 'null';
42
- if (obj === undefined) return 'undefined';
43
- if (obj === Object(obj)) return 'object';
44
- return typeof obj;
45
- };