chai 3.4.1 → 3.5.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/CODE_OF_CONDUCT.md +58 -0
- package/CONTRIBUTING.md +1 -4
- package/README.md +2 -0
- package/chai.js +279 -10
- package/lib/chai/core/assertions.js +46 -1
- package/lib/chai/interface/assert.js +99 -3
- package/lib/chai/interface/expect.js +1 -0
- package/lib/chai/interface/should.js +103 -0
- package/lib/chai/utils/addChainableMethod.js +1 -0
- package/lib/chai/utils/addMethod.js +1 -0
- package/lib/chai/utils/addProperty.js +1 -0
- package/lib/chai/utils/expectTypes.js +1 -0
- package/lib/chai/utils/flag.js +1 -0
- package/lib/chai/utils/getActual.js +2 -0
- package/lib/chai/utils/getEnumerableProperties.js +1 -0
- package/lib/chai/utils/getMessage.js +4 -3
- package/lib/chai/utils/getName.js +2 -0
- package/lib/chai/utils/getPathInfo.js +1 -0
- package/lib/chai/utils/getPathValue.js +2 -1
- package/lib/chai/utils/getProperties.js +1 -0
- package/lib/chai/utils/hasProperty.js +2 -1
- package/lib/chai/utils/inspect.js +2 -0
- package/lib/chai/utils/objDisplay.js +1 -0
- package/lib/chai/utils/overwriteChainableMethod.js +1 -0
- package/lib/chai/utils/overwriteMethod.js +1 -0
- package/lib/chai/utils/overwriteProperty.js +1 -0
- package/lib/chai/utils/test.js +2 -0
- package/lib/chai/utils/transferFlags.js +1 -0
- package/lib/chai.js +1 -1
- package/package.json +2 -2
|
@@ -48,6 +48,7 @@ module.exports = function (chai, util) {
|
|
|
48
48
|
* @param {Mixed} expected
|
|
49
49
|
* @param {String} message
|
|
50
50
|
* @param {String} operator
|
|
51
|
+
* @namespace Should
|
|
51
52
|
* @api public
|
|
52
53
|
*/
|
|
53
54
|
|
|
@@ -60,14 +61,67 @@ module.exports = function (chai, util) {
|
|
|
60
61
|
}, should.fail);
|
|
61
62
|
};
|
|
62
63
|
|
|
64
|
+
/**
|
|
65
|
+
* ### .equal(actual, expected, [message])
|
|
66
|
+
*
|
|
67
|
+
* Asserts non-strict equality (`==`) of `actual` and `expected`.
|
|
68
|
+
*
|
|
69
|
+
* should.equal(3, '3', '== coerces values to strings');
|
|
70
|
+
*
|
|
71
|
+
* @name equal
|
|
72
|
+
* @param {Mixed} actual
|
|
73
|
+
* @param {Mixed} expected
|
|
74
|
+
* @param {String} message
|
|
75
|
+
* @namespace Should
|
|
76
|
+
* @api public
|
|
77
|
+
*/
|
|
78
|
+
|
|
63
79
|
should.equal = function (val1, val2, msg) {
|
|
64
80
|
new Assertion(val1, msg).to.equal(val2);
|
|
65
81
|
};
|
|
66
82
|
|
|
83
|
+
/**
|
|
84
|
+
* ### .throw(function, [constructor/string/regexp], [string/regexp], [message])
|
|
85
|
+
*
|
|
86
|
+
* Asserts that `function` will throw an error that is an instance of
|
|
87
|
+
* `constructor`, or alternately that it will throw an error with message
|
|
88
|
+
* matching `regexp`.
|
|
89
|
+
*
|
|
90
|
+
* should.throw(fn, 'function throws a reference error');
|
|
91
|
+
* should.throw(fn, /function throws a reference error/);
|
|
92
|
+
* should.throw(fn, ReferenceError);
|
|
93
|
+
* should.throw(fn, ReferenceError, 'function throws a reference error');
|
|
94
|
+
* should.throw(fn, ReferenceError, /function throws a reference error/);
|
|
95
|
+
*
|
|
96
|
+
* @name throw
|
|
97
|
+
* @alias Throw
|
|
98
|
+
* @param {Function} function
|
|
99
|
+
* @param {ErrorConstructor} constructor
|
|
100
|
+
* @param {RegExp} regexp
|
|
101
|
+
* @param {String} message
|
|
102
|
+
* @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
|
|
103
|
+
* @namespace Should
|
|
104
|
+
* @api public
|
|
105
|
+
*/
|
|
106
|
+
|
|
67
107
|
should.Throw = function (fn, errt, errs, msg) {
|
|
68
108
|
new Assertion(fn, msg).to.Throw(errt, errs);
|
|
69
109
|
};
|
|
70
110
|
|
|
111
|
+
/**
|
|
112
|
+
* ### .exist
|
|
113
|
+
*
|
|
114
|
+
* Asserts that the target is neither `null` nor `undefined`.
|
|
115
|
+
*
|
|
116
|
+
* var foo = 'hi';
|
|
117
|
+
*
|
|
118
|
+
* should.exist(foo, 'foo exists');
|
|
119
|
+
*
|
|
120
|
+
* @name exist
|
|
121
|
+
* @namespace Should
|
|
122
|
+
* @api public
|
|
123
|
+
*/
|
|
124
|
+
|
|
71
125
|
should.exist = function (val, msg) {
|
|
72
126
|
new Assertion(val, msg).to.exist;
|
|
73
127
|
}
|
|
@@ -75,14 +129,63 @@ module.exports = function (chai, util) {
|
|
|
75
129
|
// negation
|
|
76
130
|
should.not = {}
|
|
77
131
|
|
|
132
|
+
/**
|
|
133
|
+
* ### .not.equal(actual, expected, [message])
|
|
134
|
+
*
|
|
135
|
+
* Asserts non-strict inequality (`!=`) of `actual` and `expected`.
|
|
136
|
+
*
|
|
137
|
+
* should.not.equal(3, 4, 'these numbers are not equal');
|
|
138
|
+
*
|
|
139
|
+
* @name not.equal
|
|
140
|
+
* @param {Mixed} actual
|
|
141
|
+
* @param {Mixed} expected
|
|
142
|
+
* @param {String} message
|
|
143
|
+
* @namespace Should
|
|
144
|
+
* @api public
|
|
145
|
+
*/
|
|
146
|
+
|
|
78
147
|
should.not.equal = function (val1, val2, msg) {
|
|
79
148
|
new Assertion(val1, msg).to.not.equal(val2);
|
|
80
149
|
};
|
|
81
150
|
|
|
151
|
+
/**
|
|
152
|
+
* ### .throw(function, [constructor/regexp], [message])
|
|
153
|
+
*
|
|
154
|
+
* Asserts that `function` will _not_ throw an error that is an instance of
|
|
155
|
+
* `constructor`, or alternately that it will not throw an error with message
|
|
156
|
+
* matching `regexp`.
|
|
157
|
+
*
|
|
158
|
+
* should.not.throw(fn, Error, 'function does not throw');
|
|
159
|
+
*
|
|
160
|
+
* @name not.throw
|
|
161
|
+
* @alias not.Throw
|
|
162
|
+
* @param {Function} function
|
|
163
|
+
* @param {ErrorConstructor} constructor
|
|
164
|
+
* @param {RegExp} regexp
|
|
165
|
+
* @param {String} message
|
|
166
|
+
* @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
|
|
167
|
+
* @namespace Should
|
|
168
|
+
* @api public
|
|
169
|
+
*/
|
|
170
|
+
|
|
82
171
|
should.not.Throw = function (fn, errt, errs, msg) {
|
|
83
172
|
new Assertion(fn, msg).to.not.Throw(errt, errs);
|
|
84
173
|
};
|
|
85
174
|
|
|
175
|
+
/**
|
|
176
|
+
* ### .not.exist
|
|
177
|
+
*
|
|
178
|
+
* Asserts that the target is neither `null` nor `undefined`.
|
|
179
|
+
*
|
|
180
|
+
* var bar = null;
|
|
181
|
+
*
|
|
182
|
+
* should.not.exist(bar, 'bar does not exist');
|
|
183
|
+
*
|
|
184
|
+
* @name not.exist
|
|
185
|
+
* @namespace Should
|
|
186
|
+
* @api public
|
|
187
|
+
*/
|
|
188
|
+
|
|
86
189
|
should.not.exist = function (val, msg) {
|
|
87
190
|
new Assertion(val, msg).to.not.exist;
|
|
88
191
|
}
|
|
@@ -52,6 +52,7 @@ var call = Function.prototype.call,
|
|
|
52
52
|
* @param {String} name of method to add
|
|
53
53
|
* @param {Function} method function to be used for `name`, when called
|
|
54
54
|
* @param {Function} chainingBehavior function to be called every time the property is accessed
|
|
55
|
+
* @namespace Utils
|
|
55
56
|
* @name addChainableMethod
|
|
56
57
|
* @api public
|
|
57
58
|
*/
|
|
@@ -27,6 +27,7 @@ var config = require('../config');
|
|
|
27
27
|
* @param {Object} ctx object to which the method is added
|
|
28
28
|
* @param {String} name of method to add
|
|
29
29
|
* @param {Function} method function to be used for name
|
|
30
|
+
* @namespace Utils
|
|
30
31
|
* @name addMethod
|
|
31
32
|
* @api public
|
|
32
33
|
*/
|
|
@@ -28,6 +28,7 @@ var flag = require('./flag');
|
|
|
28
28
|
* @param {Object} ctx object to which the property is added
|
|
29
29
|
* @param {String} name of property to add
|
|
30
30
|
* @param {Function} getter function to be used for name
|
|
31
|
+
* @namespace Utils
|
|
31
32
|
* @name addProperty
|
|
32
33
|
* @api public
|
|
33
34
|
*/
|
package/lib/chai/utils/flag.js
CHANGED
|
@@ -27,6 +27,7 @@ var flag = require('./flag')
|
|
|
27
27
|
*
|
|
28
28
|
* @param {Object} object (constructed Assertion)
|
|
29
29
|
* @param {Arguments} chai.Assertion.prototype.assert arguments
|
|
30
|
+
* @namespace Utils
|
|
30
31
|
* @name getMessage
|
|
31
32
|
* @api public
|
|
32
33
|
*/
|
|
@@ -42,9 +43,9 @@ module.exports = function (obj, args) {
|
|
|
42
43
|
if(typeof msg === "function") msg = msg();
|
|
43
44
|
msg = msg || '';
|
|
44
45
|
msg = msg
|
|
45
|
-
.replace(
|
|
46
|
-
.replace(
|
|
47
|
-
.replace(
|
|
46
|
+
.replace(/#\{this\}/g, function () { return objDisplay(val); })
|
|
47
|
+
.replace(/#\{act\}/g, function () { return objDisplay(actual); })
|
|
48
|
+
.replace(/#\{exp\}/g, function () { return objDisplay(expected); });
|
|
48
49
|
|
|
49
50
|
return flagMsg ? flagMsg + ': ' + msg : msg;
|
|
50
51
|
};
|
|
@@ -33,10 +33,11 @@ var getPathInfo = require('./getPathInfo');
|
|
|
33
33
|
* @param {String} path
|
|
34
34
|
* @param {Object} object
|
|
35
35
|
* @returns {Object} value or `undefined`
|
|
36
|
+
* @namespace Utils
|
|
36
37
|
* @name getPathValue
|
|
37
38
|
* @api public
|
|
38
39
|
*/
|
|
39
40
|
module.exports = function(path, obj) {
|
|
40
41
|
var info = getPathInfo(path, obj);
|
|
41
42
|
return info.value;
|
|
42
|
-
};
|
|
43
|
+
};
|
|
@@ -26,7 +26,7 @@ var type = require('type-detect');
|
|
|
26
26
|
* hasProperty('str', obj); // true
|
|
27
27
|
* hasProperty('constructor', obj); // true
|
|
28
28
|
* hasProperty('bar', obj); // false
|
|
29
|
-
*
|
|
29
|
+
*
|
|
30
30
|
* hasProperty('length', obj.str); // true
|
|
31
31
|
* hasProperty(1, obj.str); // true
|
|
32
32
|
* hasProperty(5, obj.str); // false
|
|
@@ -38,6 +38,7 @@ var type = require('type-detect');
|
|
|
38
38
|
* @param {Objuect} object
|
|
39
39
|
* @param {String|Number} name
|
|
40
40
|
* @returns {Boolean} whether it exists
|
|
41
|
+
* @namespace Utils
|
|
41
42
|
* @name getPathInfo
|
|
42
43
|
* @api public
|
|
43
44
|
*/
|
|
@@ -17,6 +17,8 @@ module.exports = inspect;
|
|
|
17
17
|
* @param {Number} depth Depth in which to descend in object. Default is 2.
|
|
18
18
|
* @param {Boolean} colors Flag to turn on ANSI escape codes to color the
|
|
19
19
|
* output. Default is false (no coloring).
|
|
20
|
+
* @namespace Utils
|
|
21
|
+
* @name inspect
|
|
20
22
|
*/
|
|
21
23
|
function inspect(obj, showHidden, depth, colors) {
|
|
22
24
|
var ctx = {
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
* @param {String} name of method / property to overwrite
|
|
33
33
|
* @param {Function} method function that returns a function to be used for name
|
|
34
34
|
* @param {Function} chainingBehavior function that returns a function to be used for property
|
|
35
|
+
* @namespace Utils
|
|
35
36
|
* @name overwriteChainableMethod
|
|
36
37
|
* @api public
|
|
37
38
|
*/
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
* @param {Object} ctx object whose method is to be overwritten
|
|
34
34
|
* @param {String} name of method to overwrite
|
|
35
35
|
* @param {Function} method function that returns a function to be used for name
|
|
36
|
+
* @namespace Utils
|
|
36
37
|
* @name overwriteMethod
|
|
37
38
|
* @api public
|
|
38
39
|
*/
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
* @param {Object} ctx object whose property is to be overwritten
|
|
34
34
|
* @param {String} name of property to overwrite
|
|
35
35
|
* @param {Function} getter function that returns a getter function to be used for name
|
|
36
|
+
* @namespace Utils
|
|
36
37
|
* @name overwriteProperty
|
|
37
38
|
* @api public
|
|
38
39
|
*/
|
package/lib/chai/utils/test.js
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
* @param {Assertion} assertion the assertion to transfer the flags from
|
|
23
23
|
* @param {Object} object the object to transfer the flags to; usually a new assertion
|
|
24
24
|
* @param {Boolean} includeAll
|
|
25
|
+
* @namespace Utils
|
|
25
26
|
* @name transferFlags
|
|
26
27
|
* @api private
|
|
27
28
|
*/
|
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": "3.
|
|
20
|
+
"version": "3.5.0",
|
|
21
21
|
"repository": {
|
|
22
22
|
"type": "git",
|
|
23
23
|
"url": "https://github.com/chaijs/chai"
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"browserify": "^10.2.1",
|
|
42
42
|
"bump-cli": "^1.1.3",
|
|
43
|
-
"karma": "^0.
|
|
43
|
+
"karma": "^0.13.16",
|
|
44
44
|
"karma-mocha": "^0.1.10",
|
|
45
45
|
"karma-sauce-launcher": "^0.2.11",
|
|
46
46
|
"karma-phantomjs-launcher": "^0.2.0",
|