chai 2.3.0 → 3.0.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.
- package/CONTRIBUTING.md +21 -17
- package/History.md +7 -0
- package/README.md +24 -84
- package/ReleaseNotes.md +7 -0
- package/bower.json +1 -1
- package/chai.js +4009 -4087
- package/karma.conf.js +1 -1
- package/lib/chai/assertion.js +2 -2
- package/lib/chai/core/assertions.js +37 -17
- package/lib/chai/interface/assert.js +17 -4
- package/lib/chai/utils/getPathInfo.js +1 -1
- package/lib/chai/utils/hasProperty.js +1 -1
- package/lib/chai/utils/index.js +1 -1
- package/lib/chai.js +1 -1
- package/package.json +13 -11
- package/lib/chai/utils/type.js +0 -45
package/karma.conf.js
CHANGED
package/lib/chai/assertion.js
CHANGED
|
@@ -81,8 +81,8 @@ module.exports = function (_chai, util) {
|
|
|
81
81
|
util.overwriteChainableMethod(this.prototype, name, fn, chainingBehavior);
|
|
82
82
|
};
|
|
83
83
|
|
|
84
|
-
|
|
85
|
-
* ### .assert(expression, message, negateMessage, expected, actual)
|
|
84
|
+
/**
|
|
85
|
+
* ### .assert(expression, message, negateMessage, expected, actual, showDiff)
|
|
86
86
|
*
|
|
87
87
|
* Executes an expression and check expectations. Throws AssertionError for reporting if test doesn't pass.
|
|
88
88
|
*
|
|
@@ -136,6 +136,12 @@ module.exports = function (chai, _) {
|
|
|
136
136
|
* expect({ foo: 'bar' }).to.be.an('object');
|
|
137
137
|
* expect(null).to.be.a('null');
|
|
138
138
|
* expect(undefined).to.be.an('undefined');
|
|
139
|
+
* expect(new Promise).to.be.a('promise');
|
|
140
|
+
* expect(new Float32Array()).to.be.a('float32array');
|
|
141
|
+
* expect(Symbol()).to.be.a('symbol');
|
|
142
|
+
*
|
|
143
|
+
* // es6 overrides
|
|
144
|
+
* expect({[Symbol.toStringTag]:()=>'foo'}).to.be.a('foo');
|
|
139
145
|
*
|
|
140
146
|
* // language chain
|
|
141
147
|
* expect(foo).to.be.an.instanceof(Foo);
|
|
@@ -835,7 +841,7 @@ module.exports = function (chai, _) {
|
|
|
835
841
|
? pathInfo.value
|
|
836
842
|
: obj[name];
|
|
837
843
|
|
|
838
|
-
if (negate &&
|
|
844
|
+
if (negate && arguments.length > 1) {
|
|
839
845
|
if (undefined === value) {
|
|
840
846
|
msg = (msg != null) ? msg + ': ' : '';
|
|
841
847
|
throw new Error(msg + _.inspect(obj) + ' has no ' + descriptor + _.inspect(name));
|
|
@@ -847,7 +853,7 @@ module.exports = function (chai, _) {
|
|
|
847
853
|
, 'expected #{this} to not have ' + descriptor + _.inspect(name));
|
|
848
854
|
}
|
|
849
855
|
|
|
850
|
-
if (
|
|
856
|
+
if (arguments.length > 1) {
|
|
851
857
|
this.assert(
|
|
852
858
|
val === value
|
|
853
859
|
, 'expected #{this} to have a ' + descriptor + _.inspect(name) + ' of #{exp}, but got #{act}'
|
|
@@ -938,16 +944,10 @@ module.exports = function (chai, _) {
|
|
|
938
944
|
Assertion.addMethod('haveOwnPropertyDescriptor', assertOwnPropertyDescriptor);
|
|
939
945
|
|
|
940
946
|
/**
|
|
941
|
-
* ### .length
|
|
942
|
-
*
|
|
943
|
-
* Asserts that the target's `length` property has
|
|
944
|
-
* the expected value.
|
|
945
|
-
*
|
|
946
|
-
* expect([ 1, 2, 3]).to.have.length(3);
|
|
947
|
-
* expect('foobar').to.have.length(6);
|
|
947
|
+
* ### .length
|
|
948
948
|
*
|
|
949
|
-
*
|
|
950
|
-
* comparison for the length property.
|
|
949
|
+
* Sets the `doLength` flag later used as a chain precursor to a value
|
|
950
|
+
* comparison for the `length` property.
|
|
951
951
|
*
|
|
952
952
|
* expect('foo').to.have.length.above(2);
|
|
953
953
|
* expect([ 1, 2, 3 ]).to.have.length.above(2);
|
|
@@ -956,8 +956,25 @@ module.exports = function (chai, _) {
|
|
|
956
956
|
* expect('foo').to.have.length.within(2,4);
|
|
957
957
|
* expect([ 1, 2, 3 ]).to.have.length.within(2,4);
|
|
958
958
|
*
|
|
959
|
+
* *Deprecation notice:* Using `length` as an assertion will be deprecated
|
|
960
|
+
* in version 2.4.0 and removed in 3.0.0. Code using the old style of
|
|
961
|
+
* asserting for `length` property value using `length(value)` should be
|
|
962
|
+
* switched to use `lengthOf(value)` instead.
|
|
963
|
+
*
|
|
959
964
|
* @name length
|
|
960
|
-
* @
|
|
965
|
+
* @api public
|
|
966
|
+
*/
|
|
967
|
+
|
|
968
|
+
/**
|
|
969
|
+
* ### .lengthOf(value[, message])
|
|
970
|
+
*
|
|
971
|
+
* Asserts that the target's `length` property has
|
|
972
|
+
* the expected value.
|
|
973
|
+
*
|
|
974
|
+
* expect([ 1, 2, 3]).to.have.lengthOf(3);
|
|
975
|
+
* expect('foobar').to.have.lengthOf(6);
|
|
976
|
+
*
|
|
977
|
+
* @name lengthOf
|
|
961
978
|
* @param {Number} length
|
|
962
979
|
* @param {String} message _optional_
|
|
963
980
|
* @api public
|
|
@@ -993,12 +1010,12 @@ module.exports = function (chai, _) {
|
|
|
993
1010
|
* expect('foobar').to.match(/^foo/);
|
|
994
1011
|
*
|
|
995
1012
|
* @name match
|
|
1013
|
+
* @alias matches
|
|
996
1014
|
* @param {RegExp} RegularExpression
|
|
997
1015
|
* @param {String} message _optional_
|
|
998
1016
|
* @api public
|
|
999
1017
|
*/
|
|
1000
|
-
|
|
1001
|
-
Assertion.addMethod('match', function (re, msg) {
|
|
1018
|
+
function assertMatch(re, msg) {
|
|
1002
1019
|
if (msg) flag(this, 'message', msg);
|
|
1003
1020
|
var obj = flag(this, 'object');
|
|
1004
1021
|
this.assert(
|
|
@@ -1006,7 +1023,10 @@ module.exports = function (chai, _) {
|
|
|
1006
1023
|
, 'expected #{this} to match ' + re
|
|
1007
1024
|
, 'expected #{this} not to match ' + re
|
|
1008
1025
|
);
|
|
1009
|
-
}
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
Assertion.addMethod('match', assertMatch);
|
|
1029
|
+
Assertion.addMethod('matches', assertMatch);
|
|
1010
1030
|
|
|
1011
1031
|
/**
|
|
1012
1032
|
* ### .string(string)
|
|
@@ -1063,7 +1083,7 @@ module.exports = function (chai, _) {
|
|
|
1063
1083
|
* expect({ foo: 1, bar: 2 }).to.have.all.keys(['bar', 'foo']);
|
|
1064
1084
|
* expect({ foo: 1, bar: 2 }).to.have.all.keys({'bar': 6, 'foo': 7});
|
|
1065
1085
|
* expect({ foo: 1, bar: 2, baz: 3 }).to.contain.all.keys(['bar', 'foo']);
|
|
1066
|
-
* expect({ foo: 1, bar: 2, baz: 3 }).to.contain.all.keys(
|
|
1086
|
+
* expect({ foo: 1, bar: 2, baz: 3 }).to.contain.all.keys({'bar': 6});
|
|
1067
1087
|
*
|
|
1068
1088
|
*
|
|
1069
1089
|
* @name keys
|
|
@@ -1255,7 +1275,7 @@ module.exports = function (chai, _) {
|
|
|
1255
1275
|
}
|
|
1256
1276
|
|
|
1257
1277
|
// next, check message
|
|
1258
|
-
var message = '
|
|
1278
|
+
var message = 'error' === _.type(err) && "message" in err
|
|
1259
1279
|
? err.message
|
|
1260
1280
|
: '' + err;
|
|
1261
1281
|
|
|
@@ -700,7 +700,7 @@ module.exports = function (chai, util) {
|
|
|
700
700
|
*
|
|
701
701
|
* Asserts that `haystack` does not include `needle`. Works
|
|
702
702
|
* for strings and arrays.
|
|
703
|
-
*
|
|
703
|
+
*
|
|
704
704
|
* assert.notInclude('foobar', 'baz', 'string not include substring');
|
|
705
705
|
* assert.notInclude([ 1, 2, 3 ], 4, 'array not include contain value');
|
|
706
706
|
*
|
|
@@ -1243,11 +1243,24 @@ module.exports = function (chai, util) {
|
|
|
1243
1243
|
}
|
|
1244
1244
|
|
|
1245
1245
|
/*!
|
|
1246
|
-
*
|
|
1246
|
+
* ### .ifError(object)
|
|
1247
|
+
*
|
|
1248
|
+
* Asserts if value is not a false value, and throws if it is a true value.
|
|
1249
|
+
* This is added to allow for chai to be a drop-in replacement for Node's
|
|
1250
|
+
* assert class.
|
|
1251
|
+
*
|
|
1252
|
+
* var err = new Error('I am a custom error');
|
|
1253
|
+
* assert.ifError(err); // Rethrows err!
|
|
1254
|
+
*
|
|
1255
|
+
* @name ifError
|
|
1256
|
+
* @param {Object} object
|
|
1257
|
+
* @api public
|
|
1247
1258
|
*/
|
|
1248
1259
|
|
|
1249
|
-
assert.ifError = function (val
|
|
1250
|
-
|
|
1260
|
+
assert.ifError = function (val) {
|
|
1261
|
+
if (val) {
|
|
1262
|
+
throw(val);
|
|
1263
|
+
}
|
|
1251
1264
|
};
|
|
1252
1265
|
|
|
1253
1266
|
/*!
|
|
@@ -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
|
|
package/lib/chai/utils/index.js
CHANGED
package/lib/chai.js
CHANGED
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": "
|
|
20
|
+
"version": "3.0.0",
|
|
21
21
|
"repository": {
|
|
22
22
|
"type": "git",
|
|
23
23
|
"url": "https://github.com/chaijs/chai"
|
|
@@ -33,17 +33,19 @@
|
|
|
33
33
|
"node": ">= 0.4.0"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"assertion-error": "1.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
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"karma
|
|
43
|
-
"karma-
|
|
44
|
-
"karma-
|
|
45
|
-
"karma-
|
|
46
|
-
"
|
|
47
|
-
"
|
|
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"
|
|
48
50
|
}
|
|
49
51
|
}
|
package/lib/chai/utils/type.js
DELETED
|
@@ -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
|
-
};
|