chai 1.9.1 → 1.9.2
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/History.md +22 -0
- package/README.md +1 -1
- package/ReleaseNotes.md +25 -0
- package/bower.json +1 -1
- package/chai.js +50 -28
- package/lib/chai/assertion.js +2 -2
- package/lib/chai/core/assertions.js +14 -3
- package/lib/chai/interface/assert.js +2 -2
- package/lib/chai/utils/getMessage.js +1 -0
- package/lib/chai/utils/inspect.js +30 -20
- package/lib/chai.js +1 -1
- package/package.json +2 -2
package/History.md
CHANGED
|
@@ -1,4 +1,26 @@
|
|
|
1
1
|
|
|
2
|
+
1.9.2 / 2014-09-29
|
|
3
|
+
==================
|
|
4
|
+
|
|
5
|
+
* Merge pull request #268 from charlierudolph/cr-lazyMessages
|
|
6
|
+
* Merge pull request #269 from charlierudolph/cr-codeCleanup
|
|
7
|
+
* Merge pull request #277 from charlierudolph/fix-doc
|
|
8
|
+
* Merge pull request #279 from mohayonao/fix-closeTo
|
|
9
|
+
* Merge pull request #292 from boneskull/mocha
|
|
10
|
+
* resolves #255: upgrade mocha
|
|
11
|
+
* Merge pull request #289 from charlierudolph/cr-dryUpCode
|
|
12
|
+
* Dry up code
|
|
13
|
+
* Merge pull request #275 from DrRataplan/master
|
|
14
|
+
* assert: .closeTo() verify value's type before assertion
|
|
15
|
+
* Rewrite pretty-printing HTML elements to prevent throwing internal errors Fixes errors occuring when using a non-native DOM implementation
|
|
16
|
+
* Fix assert documentation
|
|
17
|
+
* Remove unused argument
|
|
18
|
+
* Allow messages to be functions
|
|
19
|
+
* Merge pull request #267 from shinnn/master
|
|
20
|
+
* Use SVG badge
|
|
21
|
+
* Merge pull request #264 from cjthompson/keys_diff
|
|
22
|
+
* Show diff for keys assertion
|
|
23
|
+
|
|
2
24
|
1.9.1 / 2014-03-19
|
|
3
25
|
==================
|
|
4
26
|
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ can be delightfully paired with any javascript testing framework.
|
|
|
5
5
|
|
|
6
6
|
For more information or to download plugins, view the [documentation](http://chaijs.com).
|
|
7
7
|
|
|
8
|
-
[](https://travis-ci.org/chaijs/chai)
|
|
9
9
|
|
|
10
10
|
[](https://saucelabs.com/u/chaijs)
|
|
11
11
|
|
package/ReleaseNotes.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# Release Notes
|
|
2
2
|
|
|
3
|
+
## 1.9.2 / 2014-09-29
|
|
4
|
+
|
|
5
|
+
The following changes are required if you are upgrading from the previous version:
|
|
6
|
+
|
|
7
|
+
- **Users:**
|
|
8
|
+
- No changes required
|
|
9
|
+
- **Plugin Developers:**
|
|
10
|
+
- No changes required
|
|
11
|
+
- **Core Contributors:**
|
|
12
|
+
- Refresh `node_modules` folder for updated dependencies.
|
|
13
|
+
|
|
14
|
+
### Community Contributions
|
|
15
|
+
|
|
16
|
+
- [#264](https://github.com/chaijs/chai/pull/264) Show diff for keys assertions [@cjthompson](https://github.com/cjthompson)
|
|
17
|
+
- [#267](https://github.com/chaijs/chai/pull/267) Use SVG badges [@shinnn](https://github.com/shinnn)
|
|
18
|
+
- [#268](https://github.com/chaijs/chai/pull/268) Allow messages to be functions (sinon-compat) [@charlierudolph](https://github.com/charlierudolph)
|
|
19
|
+
- [#269](https://github.com/chaijs/chai/pull/269) Remove unused argument for #lengthOf [@charlierudolph](https://github.com/charlierudolph)
|
|
20
|
+
- [#275](https://github.com/chaijs/chai/pull/275) Rewrite pretty-printing HTML elements to prevent throwing internal errors [@DrRataplan](https://github.com/DrRataplan)
|
|
21
|
+
- [#277](https://github.com/chaijs/chai/pull/277) Fix assert documentation for #sameMembers [@charlierudolph](https://github.com/charlierudolph)
|
|
22
|
+
- [#279](https://github.com/chaijs/chai/pull/279) closeTo should check value's type before assertion [@mohayonao](https://github.com/mohayonao)
|
|
23
|
+
- [#289](https://github.com/chaijs/chai/pull/289) satisfy is called twice [@charlierudolph](https://github.com/charlierudolph)
|
|
24
|
+
- [#292](https://github.com/chaijs/chai/pull/292) resolve conflicts with node-webkit and global usage [@boneskull](https://github.com/boneskull)
|
|
25
|
+
|
|
26
|
+
Thank you to all who took time to contribute!
|
|
27
|
+
|
|
3
28
|
## 1.9.1 / 2014-03-19
|
|
4
29
|
|
|
5
30
|
The following changes are required if you are upgrading from the previous version:
|
package/bower.json
CHANGED
package/chai.js
CHANGED
|
@@ -736,7 +736,7 @@ var used = []
|
|
|
736
736
|
* Chai version
|
|
737
737
|
*/
|
|
738
738
|
|
|
739
|
-
exports.version = '1.9.
|
|
739
|
+
exports.version = '1.9.2';
|
|
740
740
|
|
|
741
741
|
/*!
|
|
742
742
|
* Assertion Error
|
|
@@ -903,8 +903,8 @@ module.exports = function (_chai, util) {
|
|
|
903
903
|
*
|
|
904
904
|
* @name assert
|
|
905
905
|
* @param {Philosophical} expression to be tested
|
|
906
|
-
* @param {String} message to display if fails
|
|
907
|
-
* @param {String} negatedMessage to display if negated expression fails
|
|
906
|
+
* @param {String or Function} message or function that returns message to display if fails
|
|
907
|
+
* @param {String or Function} negatedMessage or function that returns negatedMessage to display if negated expression fails
|
|
908
908
|
* @param {Mixed} expected value (remember to check for negation)
|
|
909
909
|
* @param {Mixed} actual (optional) will default to `this.obj`
|
|
910
910
|
* @api private
|
|
@@ -1872,7 +1872,7 @@ module.exports = function (chai, _) {
|
|
|
1872
1872
|
}
|
|
1873
1873
|
|
|
1874
1874
|
Assertion.addChainableMethod('length', assertLength, assertLengthChain);
|
|
1875
|
-
Assertion.addMethod('lengthOf', assertLength
|
|
1875
|
+
Assertion.addMethod('lengthOf', assertLength);
|
|
1876
1876
|
|
|
1877
1877
|
/**
|
|
1878
1878
|
* ### .match(regexp)
|
|
@@ -1951,6 +1951,7 @@ module.exports = function (chai, _) {
|
|
|
1951
1951
|
if (!keys.length) throw new Error('keys required');
|
|
1952
1952
|
|
|
1953
1953
|
var actual = Object.keys(obj)
|
|
1954
|
+
, expected = keys
|
|
1954
1955
|
, len = keys.length;
|
|
1955
1956
|
|
|
1956
1957
|
// Inclusion
|
|
@@ -1985,6 +1986,9 @@ module.exports = function (chai, _) {
|
|
|
1985
1986
|
ok
|
|
1986
1987
|
, 'expected #{this} to ' + str
|
|
1987
1988
|
, 'expected #{this} to not ' + str
|
|
1989
|
+
, expected.sort()
|
|
1990
|
+
, actual.sort()
|
|
1991
|
+
, true
|
|
1988
1992
|
);
|
|
1989
1993
|
}
|
|
1990
1994
|
|
|
@@ -2220,12 +2224,13 @@ module.exports = function (chai, _) {
|
|
|
2220
2224
|
Assertion.addMethod('satisfy', function (matcher, msg) {
|
|
2221
2225
|
if (msg) flag(this, 'message', msg);
|
|
2222
2226
|
var obj = flag(this, 'object');
|
|
2227
|
+
var result = matcher(obj);
|
|
2223
2228
|
this.assert(
|
|
2224
|
-
|
|
2229
|
+
result
|
|
2225
2230
|
, 'expected #{this} to satisfy ' + _.objDisplay(matcher)
|
|
2226
2231
|
, 'expected #{this} to not satisfy' + _.objDisplay(matcher)
|
|
2227
2232
|
, this.negate ? false : true
|
|
2228
|
-
,
|
|
2233
|
+
, result
|
|
2229
2234
|
);
|
|
2230
2235
|
});
|
|
2231
2236
|
|
|
@@ -2246,6 +2251,12 @@ module.exports = function (chai, _) {
|
|
|
2246
2251
|
Assertion.addMethod('closeTo', function (expected, delta, msg) {
|
|
2247
2252
|
if (msg) flag(this, 'message', msg);
|
|
2248
2253
|
var obj = flag(this, 'object');
|
|
2254
|
+
|
|
2255
|
+
new Assertion(obj, msg).is.a('number');
|
|
2256
|
+
if (_.type(expected) !== 'number' || _.type(delta) !== 'number') {
|
|
2257
|
+
throw new Error('the arguments to closeTo must be numbers');
|
|
2258
|
+
}
|
|
2259
|
+
|
|
2249
2260
|
this.assert(
|
|
2250
2261
|
Math.abs(obj - expected) <= delta
|
|
2251
2262
|
, 'expected #{this} to be close to ' + expected + ' +/- ' + delta
|
|
@@ -3324,8 +3335,8 @@ module.exports = function (chai, util) {
|
|
|
3324
3335
|
* assert.sameMembers([ 1, 2, 3 ], [ 2, 1, 3 ], 'same members');
|
|
3325
3336
|
*
|
|
3326
3337
|
* @name sameMembers
|
|
3327
|
-
* @param {Array}
|
|
3328
|
-
* @param {Array}
|
|
3338
|
+
* @param {Array} set1
|
|
3339
|
+
* @param {Array} set2
|
|
3329
3340
|
* @param {String} message
|
|
3330
3341
|
* @api public
|
|
3331
3342
|
*/
|
|
@@ -3799,6 +3810,7 @@ module.exports = function (obj, args) {
|
|
|
3799
3810
|
, msg = negate ? args[2] : args[1]
|
|
3800
3811
|
, flagMsg = flag(obj, 'message');
|
|
3801
3812
|
|
|
3813
|
+
if(typeof msg === "function") msg = msg();
|
|
3802
3814
|
msg = msg || '';
|
|
3803
3815
|
msg = msg
|
|
3804
3816
|
.replace(/#{this}/g, objDisplay(val))
|
|
@@ -4122,24 +4134,6 @@ function inspect(obj, showHidden, depth, colors) {
|
|
|
4122
4134
|
return formatValue(ctx, obj, (typeof depth === 'undefined' ? 2 : depth));
|
|
4123
4135
|
}
|
|
4124
4136
|
|
|
4125
|
-
// https://gist.github.com/1044128/
|
|
4126
|
-
var getOuterHTML = function(element) {
|
|
4127
|
-
if ('outerHTML' in element) return element.outerHTML;
|
|
4128
|
-
var ns = "http://www.w3.org/1999/xhtml";
|
|
4129
|
-
var container = document.createElementNS(ns, '_');
|
|
4130
|
-
var elemProto = (window.HTMLElement || window.Element).prototype;
|
|
4131
|
-
var xmlSerializer = new XMLSerializer();
|
|
4132
|
-
var html;
|
|
4133
|
-
if (document.xmlVersion) {
|
|
4134
|
-
return xmlSerializer.serializeToString(element);
|
|
4135
|
-
} else {
|
|
4136
|
-
container.appendChild(element.cloneNode(false));
|
|
4137
|
-
html = container.innerHTML.replace('><', '>' + element.innerHTML + '<');
|
|
4138
|
-
container.innerHTML = '';
|
|
4139
|
-
return html;
|
|
4140
|
-
}
|
|
4141
|
-
};
|
|
4142
|
-
|
|
4143
4137
|
// Returns true if object is a DOM element.
|
|
4144
4138
|
var isDOMElement = function (object) {
|
|
4145
4139
|
if (typeof HTMLElement === 'object') {
|
|
@@ -4173,9 +4167,37 @@ function formatValue(ctx, value, recurseTimes) {
|
|
|
4173
4167
|
return primitive;
|
|
4174
4168
|
}
|
|
4175
4169
|
|
|
4176
|
-
// If
|
|
4170
|
+
// If this is a DOM element, try to get the outer HTML.
|
|
4177
4171
|
if (isDOMElement(value)) {
|
|
4178
|
-
|
|
4172
|
+
if ('outerHTML' in value) {
|
|
4173
|
+
return value.outerHTML;
|
|
4174
|
+
// This value does not have an outerHTML attribute,
|
|
4175
|
+
// it could still be an XML element
|
|
4176
|
+
} else {
|
|
4177
|
+
// Attempt to serialize it
|
|
4178
|
+
try {
|
|
4179
|
+
if (document.xmlVersion) {
|
|
4180
|
+
var xmlSerializer = new XMLSerializer();
|
|
4181
|
+
return xmlSerializer.serializeToString(value);
|
|
4182
|
+
} else {
|
|
4183
|
+
// Firefox 11- do not support outerHTML
|
|
4184
|
+
// It does, however, support innerHTML
|
|
4185
|
+
// Use the following to render the element
|
|
4186
|
+
var ns = "http://www.w3.org/1999/xhtml";
|
|
4187
|
+
var container = document.createElementNS(ns, '_');
|
|
4188
|
+
|
|
4189
|
+
container.appendChild(value.cloneNode(false));
|
|
4190
|
+
html = container.innerHTML
|
|
4191
|
+
.replace('><', '>' + value.innerHTML + '<');
|
|
4192
|
+
container.innerHTML = '';
|
|
4193
|
+
return html;
|
|
4194
|
+
}
|
|
4195
|
+
} catch (err) {
|
|
4196
|
+
// This could be a non-native DOM implementation,
|
|
4197
|
+
// continue with the normal flow:
|
|
4198
|
+
// printing the element as if it is an object.
|
|
4199
|
+
}
|
|
4200
|
+
}
|
|
4179
4201
|
}
|
|
4180
4202
|
|
|
4181
4203
|
// Look up the keys of the object.
|
package/lib/chai/assertion.js
CHANGED
|
@@ -88,8 +88,8 @@ module.exports = function (_chai, util) {
|
|
|
88
88
|
*
|
|
89
89
|
* @name assert
|
|
90
90
|
* @param {Philosophical} expression to be tested
|
|
91
|
-
* @param {String} message to display if fails
|
|
92
|
-
* @param {String} negatedMessage to display if negated expression fails
|
|
91
|
+
* @param {String or Function} message or function that returns message to display if fails
|
|
92
|
+
* @param {String or Function} negatedMessage or function that returns negatedMessage to display if negated expression fails
|
|
93
93
|
* @param {Mixed} expected value (remember to check for negation)
|
|
94
94
|
* @param {Mixed} actual (optional) will default to `this.obj`
|
|
95
95
|
* @api private
|
|
@@ -871,7 +871,7 @@ module.exports = function (chai, _) {
|
|
|
871
871
|
}
|
|
872
872
|
|
|
873
873
|
Assertion.addChainableMethod('length', assertLength, assertLengthChain);
|
|
874
|
-
Assertion.addMethod('lengthOf', assertLength
|
|
874
|
+
Assertion.addMethod('lengthOf', assertLength);
|
|
875
875
|
|
|
876
876
|
/**
|
|
877
877
|
* ### .match(regexp)
|
|
@@ -950,6 +950,7 @@ module.exports = function (chai, _) {
|
|
|
950
950
|
if (!keys.length) throw new Error('keys required');
|
|
951
951
|
|
|
952
952
|
var actual = Object.keys(obj)
|
|
953
|
+
, expected = keys
|
|
953
954
|
, len = keys.length;
|
|
954
955
|
|
|
955
956
|
// Inclusion
|
|
@@ -984,6 +985,9 @@ module.exports = function (chai, _) {
|
|
|
984
985
|
ok
|
|
985
986
|
, 'expected #{this} to ' + str
|
|
986
987
|
, 'expected #{this} to not ' + str
|
|
988
|
+
, expected.sort()
|
|
989
|
+
, actual.sort()
|
|
990
|
+
, true
|
|
987
991
|
);
|
|
988
992
|
}
|
|
989
993
|
|
|
@@ -1219,12 +1223,13 @@ module.exports = function (chai, _) {
|
|
|
1219
1223
|
Assertion.addMethod('satisfy', function (matcher, msg) {
|
|
1220
1224
|
if (msg) flag(this, 'message', msg);
|
|
1221
1225
|
var obj = flag(this, 'object');
|
|
1226
|
+
var result = matcher(obj);
|
|
1222
1227
|
this.assert(
|
|
1223
|
-
|
|
1228
|
+
result
|
|
1224
1229
|
, 'expected #{this} to satisfy ' + _.objDisplay(matcher)
|
|
1225
1230
|
, 'expected #{this} to not satisfy' + _.objDisplay(matcher)
|
|
1226
1231
|
, this.negate ? false : true
|
|
1227
|
-
,
|
|
1232
|
+
, result
|
|
1228
1233
|
);
|
|
1229
1234
|
});
|
|
1230
1235
|
|
|
@@ -1245,6 +1250,12 @@ module.exports = function (chai, _) {
|
|
|
1245
1250
|
Assertion.addMethod('closeTo', function (expected, delta, msg) {
|
|
1246
1251
|
if (msg) flag(this, 'message', msg);
|
|
1247
1252
|
var obj = flag(this, 'object');
|
|
1253
|
+
|
|
1254
|
+
new Assertion(obj, msg).is.a('number');
|
|
1255
|
+
if (_.type(expected) !== 'number' || _.type(delta) !== 'number') {
|
|
1256
|
+
throw new Error('the arguments to closeTo must be numbers');
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1248
1259
|
this.assert(
|
|
1249
1260
|
Math.abs(obj - expected) <= delta
|
|
1250
1261
|
, 'expected #{this} to be close to ' + expected + ' +/- ' + delta
|
|
@@ -1006,8 +1006,8 @@ module.exports = function (chai, util) {
|
|
|
1006
1006
|
* assert.sameMembers([ 1, 2, 3 ], [ 2, 1, 3 ], 'same members');
|
|
1007
1007
|
*
|
|
1008
1008
|
* @name sameMembers
|
|
1009
|
-
* @param {Array}
|
|
1010
|
-
* @param {Array}
|
|
1009
|
+
* @param {Array} set1
|
|
1010
|
+
* @param {Array} set2
|
|
1011
1011
|
* @param {String} message
|
|
1012
1012
|
* @api public
|
|
1013
1013
|
*/
|
|
@@ -27,24 +27,6 @@ function inspect(obj, showHidden, depth, colors) {
|
|
|
27
27
|
return formatValue(ctx, obj, (typeof depth === 'undefined' ? 2 : depth));
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
// https://gist.github.com/1044128/
|
|
31
|
-
var getOuterHTML = function(element) {
|
|
32
|
-
if ('outerHTML' in element) return element.outerHTML;
|
|
33
|
-
var ns = "http://www.w3.org/1999/xhtml";
|
|
34
|
-
var container = document.createElementNS(ns, '_');
|
|
35
|
-
var elemProto = (window.HTMLElement || window.Element).prototype;
|
|
36
|
-
var xmlSerializer = new XMLSerializer();
|
|
37
|
-
var html;
|
|
38
|
-
if (document.xmlVersion) {
|
|
39
|
-
return xmlSerializer.serializeToString(element);
|
|
40
|
-
} else {
|
|
41
|
-
container.appendChild(element.cloneNode(false));
|
|
42
|
-
html = container.innerHTML.replace('><', '>' + element.innerHTML + '<');
|
|
43
|
-
container.innerHTML = '';
|
|
44
|
-
return html;
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
|
|
48
30
|
// Returns true if object is a DOM element.
|
|
49
31
|
var isDOMElement = function (object) {
|
|
50
32
|
if (typeof HTMLElement === 'object') {
|
|
@@ -78,9 +60,37 @@ function formatValue(ctx, value, recurseTimes) {
|
|
|
78
60
|
return primitive;
|
|
79
61
|
}
|
|
80
62
|
|
|
81
|
-
// If
|
|
63
|
+
// If this is a DOM element, try to get the outer HTML.
|
|
82
64
|
if (isDOMElement(value)) {
|
|
83
|
-
|
|
65
|
+
if ('outerHTML' in value) {
|
|
66
|
+
return value.outerHTML;
|
|
67
|
+
// This value does not have an outerHTML attribute,
|
|
68
|
+
// it could still be an XML element
|
|
69
|
+
} else {
|
|
70
|
+
// Attempt to serialize it
|
|
71
|
+
try {
|
|
72
|
+
if (document.xmlVersion) {
|
|
73
|
+
var xmlSerializer = new XMLSerializer();
|
|
74
|
+
return xmlSerializer.serializeToString(value);
|
|
75
|
+
} else {
|
|
76
|
+
// Firefox 11- do not support outerHTML
|
|
77
|
+
// It does, however, support innerHTML
|
|
78
|
+
// Use the following to render the element
|
|
79
|
+
var ns = "http://www.w3.org/1999/xhtml";
|
|
80
|
+
var container = document.createElementNS(ns, '_');
|
|
81
|
+
|
|
82
|
+
container.appendChild(value.cloneNode(false));
|
|
83
|
+
html = container.innerHTML
|
|
84
|
+
.replace('><', '>' + value.innerHTML + '<');
|
|
85
|
+
container.innerHTML = '';
|
|
86
|
+
return html;
|
|
87
|
+
}
|
|
88
|
+
} catch (err) {
|
|
89
|
+
// This could be a non-native DOM implementation,
|
|
90
|
+
// continue with the normal flow:
|
|
91
|
+
// printing the element as if it is an object.
|
|
92
|
+
}
|
|
93
|
+
}
|
|
84
94
|
}
|
|
85
95
|
|
|
86
96
|
// Look up the keys of the object.
|
package/lib/chai.js
CHANGED
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"Veselin Todorov <hi@vesln.com>",
|
|
12
12
|
"John Firebaugh <john.firebaugh@gmail.com>"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.9.
|
|
14
|
+
"version": "1.9.2",
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
|
17
17
|
"url": "https://github.com/chaijs/chai"
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
, "karma-mocha": "*"
|
|
37
37
|
, "karma-sauce-launcher": "0.2.x"
|
|
38
38
|
, "karma-phantomjs-launcher": "0.1.1"
|
|
39
|
-
, "mocha": "1.
|
|
39
|
+
, "mocha": "1.21.x"
|
|
40
40
|
, "istanbul": "0.2.x"
|
|
41
41
|
}
|
|
42
42
|
}
|