chai 1.8.0 → 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/.npmignore +1 -1
- package/CONTRIBUTING.md +173 -0
- package/History.md +93 -0
- package/README.md +60 -40
- package/ReleaseNotes.md +156 -0
- package/bower.json +1 -1
- package/chai.js +354 -163
- package/karma.conf.js +4 -5
- package/lib/chai/assertion.js +31 -31
- package/lib/chai/config.js +50 -0
- package/lib/chai/core/assertions.js +76 -21
- package/lib/chai/interface/assert.js +15 -39
- package/lib/chai/interface/expect.js +1 -1
- package/lib/chai/interface/should.js +27 -25
- package/lib/chai/utils/addChainableMethod.js +22 -5
- package/lib/chai/utils/addMethod.js +7 -1
- package/lib/chai/utils/addProperty.js +1 -1
- package/lib/chai/utils/flag.js +1 -1
- package/lib/chai/utils/getActual.js +2 -3
- package/lib/chai/utils/getEnumerableProperties.js +1 -1
- package/lib/chai/utils/getMessage.js +2 -1
- package/lib/chai/utils/getName.js +1 -1
- package/lib/chai/utils/getPathValue.js +1 -1
- package/lib/chai/utils/getProperties.js +1 -1
- package/lib/chai/utils/index.js +6 -0
- package/lib/chai/utils/inspect.js +30 -20
- package/lib/chai/utils/objDisplay.js +3 -2
- package/lib/chai/utils/overwriteChainableMethod.js +53 -0
- package/lib/chai/utils/overwriteMethod.js +1 -1
- package/lib/chai/utils/overwriteProperty.js +1 -1
- package/lib/chai/utils/test.js +1 -1
- package/lib/chai/utils/transferFlags.js +1 -1
- package/lib/chai/utils/type.js +1 -1
- package/lib/chai.js +9 -2
- package/package.json +7 -8
package/karma.conf.js
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
module.exports = function(config) {
|
|
2
2
|
config.set({
|
|
3
|
-
|
|
4
|
-
, frameworks: [ 'mocha' ]
|
|
3
|
+
frameworks: [ 'mocha' ]
|
|
5
4
|
, files: [
|
|
6
5
|
'build/build.js'
|
|
7
6
|
, 'test/bootstrap/karma.js'
|
|
8
7
|
, 'test/*.js'
|
|
9
8
|
]
|
|
10
|
-
, exclude: []
|
|
11
9
|
, reporters: [ 'progress' ]
|
|
12
|
-
, port: 9876
|
|
13
10
|
, colors: true
|
|
14
11
|
, logLevel: config.LOG_INFO
|
|
15
12
|
, autoWatch: false
|
|
16
13
|
, browsers: [ 'PhantomJS' ]
|
|
17
|
-
,
|
|
14
|
+
, browserDisconnectTimeout: 10000
|
|
15
|
+
, browserDisconnectTolerance: 2
|
|
16
|
+
, browserNoActivityTimeout: 20000
|
|
18
17
|
, singleRun: true
|
|
19
18
|
});
|
|
20
19
|
|
package/lib/chai/assertion.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* chai
|
|
3
3
|
* http://chaijs.com
|
|
4
|
-
* Copyright(c) 2011-
|
|
4
|
+
* Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
|
|
5
5
|
* MIT Licensed
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
var config = require('./config');
|
|
9
|
+
|
|
8
10
|
module.exports = function (_chai, util) {
|
|
9
11
|
/*!
|
|
10
12
|
* Module dependencies.
|
|
@@ -33,33 +35,27 @@ module.exports = function (_chai, util) {
|
|
|
33
35
|
flag(this, 'message', msg);
|
|
34
36
|
}
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
*/
|
|
47
|
-
|
|
48
|
-
Assertion.includeStack = false;
|
|
49
|
-
|
|
50
|
-
/*!
|
|
51
|
-
* ### Assertion.showDiff
|
|
52
|
-
*
|
|
53
|
-
* User configurable property, influences whether or not
|
|
54
|
-
* the `showDiff` flag should be included in the thrown
|
|
55
|
-
* AssertionErrors. `false` will always be `false`; `true`
|
|
56
|
-
* will be true when the assertion has requested a diff
|
|
57
|
-
* be shown.
|
|
58
|
-
*
|
|
59
|
-
* @api public
|
|
60
|
-
*/
|
|
38
|
+
Object.defineProperty(Assertion, 'includeStack', {
|
|
39
|
+
get: function() {
|
|
40
|
+
console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
|
|
41
|
+
return config.includeStack;
|
|
42
|
+
},
|
|
43
|
+
set: function(value) {
|
|
44
|
+
console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
|
|
45
|
+
config.includeStack = value;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
61
48
|
|
|
62
|
-
Assertion
|
|
49
|
+
Object.defineProperty(Assertion, 'showDiff', {
|
|
50
|
+
get: function() {
|
|
51
|
+
console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
|
|
52
|
+
return config.showDiff;
|
|
53
|
+
},
|
|
54
|
+
set: function(value) {
|
|
55
|
+
console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
|
|
56
|
+
config.showDiff = value;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
63
59
|
|
|
64
60
|
Assertion.addProperty = function (name, fn) {
|
|
65
61
|
util.addProperty(this.prototype, name, fn);
|
|
@@ -81,6 +77,10 @@ module.exports = function (_chai, util) {
|
|
|
81
77
|
util.overwriteMethod(this.prototype, name, fn);
|
|
82
78
|
};
|
|
83
79
|
|
|
80
|
+
Assertion.overwriteChainableMethod = function (name, fn, chainingBehavior) {
|
|
81
|
+
util.overwriteChainableMethod(this.prototype, name, fn, chainingBehavior);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
84
|
/*!
|
|
85
85
|
* ### .assert(expression, message, negateMessage, expected, actual)
|
|
86
86
|
*
|
|
@@ -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
|
|
@@ -98,7 +98,7 @@ module.exports = function (_chai, util) {
|
|
|
98
98
|
Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual, showDiff) {
|
|
99
99
|
var ok = util.test(this, arguments);
|
|
100
100
|
if (true !== showDiff) showDiff = false;
|
|
101
|
-
if (true !==
|
|
101
|
+
if (true !== config.showDiff) showDiff = false;
|
|
102
102
|
|
|
103
103
|
if (!ok) {
|
|
104
104
|
var msg = util.getMessage(this, arguments)
|
|
@@ -107,7 +107,7 @@ module.exports = function (_chai, util) {
|
|
|
107
107
|
actual: actual
|
|
108
108
|
, expected: expected
|
|
109
109
|
, showDiff: showDiff
|
|
110
|
-
}, (
|
|
110
|
+
}, (config.includeStack) ? this.assert : flag(this, 'ssfi'));
|
|
111
111
|
}
|
|
112
112
|
};
|
|
113
113
|
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ### config.includeStack
|
|
5
|
+
*
|
|
6
|
+
* User configurable property, influences whether stack trace
|
|
7
|
+
* is included in Assertion error message. Default of false
|
|
8
|
+
* suppresses stack trace in the error message.
|
|
9
|
+
*
|
|
10
|
+
* chai.config.includeStack = true; // enable stack on error
|
|
11
|
+
*
|
|
12
|
+
* @param {Boolean}
|
|
13
|
+
* @api public
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
includeStack: false,
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* ### config.showDiff
|
|
20
|
+
*
|
|
21
|
+
* User configurable property, influences whether or not
|
|
22
|
+
* the `showDiff` flag should be included in the thrown
|
|
23
|
+
* AssertionErrors. `false` will always be `false`; `true`
|
|
24
|
+
* will be true when the assertion has requested a diff
|
|
25
|
+
* be shown.
|
|
26
|
+
*
|
|
27
|
+
* @param {Boolean}
|
|
28
|
+
* @api public
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
showDiff: true,
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* ### config.truncateThreshold
|
|
35
|
+
*
|
|
36
|
+
* User configurable property, sets length threshold for actual and
|
|
37
|
+
* expected values in assertion errors. If this threshold is exceeded,
|
|
38
|
+
* the value is truncated.
|
|
39
|
+
*
|
|
40
|
+
* Set it to zero if you want to disable truncating altogether.
|
|
41
|
+
*
|
|
42
|
+
* chai.config.truncateThreshold = 0; // disable truncating
|
|
43
|
+
*
|
|
44
|
+
* @param {Number}
|
|
45
|
+
* @api public
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
truncateThreshold: 40
|
|
49
|
+
|
|
50
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* chai
|
|
3
3
|
* http://chaijs.com
|
|
4
|
-
* Copyright(c) 2011-
|
|
4
|
+
* Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
|
|
5
5
|
* MIT Licensed
|
|
6
6
|
*/
|
|
7
7
|
|
|
@@ -13,9 +13,9 @@ module.exports = function (chai, _) {
|
|
|
13
13
|
/**
|
|
14
14
|
* ### Language Chains
|
|
15
15
|
*
|
|
16
|
-
* The following are
|
|
16
|
+
* The following are provided as chainable getters to
|
|
17
17
|
* improve the readability of your assertions. They
|
|
18
|
-
* do not provide
|
|
18
|
+
* do not provide testing capabilities unless they
|
|
19
19
|
* have been overwritten by a plugin.
|
|
20
20
|
*
|
|
21
21
|
* **Chains**
|
|
@@ -26,6 +26,7 @@ module.exports = function (chai, _) {
|
|
|
26
26
|
* - is
|
|
27
27
|
* - that
|
|
28
28
|
* - and
|
|
29
|
+
* - has
|
|
29
30
|
* - have
|
|
30
31
|
* - with
|
|
31
32
|
* - at
|
|
@@ -37,7 +38,7 @@ module.exports = function (chai, _) {
|
|
|
37
38
|
*/
|
|
38
39
|
|
|
39
40
|
[ 'to', 'be', 'been'
|
|
40
|
-
, 'is', 'and', 'have'
|
|
41
|
+
, 'is', 'and', 'has', 'have'
|
|
41
42
|
, 'with', 'that', 'at'
|
|
42
43
|
, 'of', 'same' ].forEach(function (chain) {
|
|
43
44
|
Assertion.addProperty(chain, function () {
|
|
@@ -145,9 +146,28 @@ module.exports = function (chai, _) {
|
|
|
145
146
|
|
|
146
147
|
function include (val, msg) {
|
|
147
148
|
if (msg) flag(this, 'message', msg);
|
|
148
|
-
var obj = flag(this, 'object')
|
|
149
|
+
var obj = flag(this, 'object');
|
|
150
|
+
var expected = false;
|
|
151
|
+
if (_.type(obj) === 'array' && _.type(val) === 'object') {
|
|
152
|
+
for (var i in obj) {
|
|
153
|
+
if (_.eql(obj[i], val)) {
|
|
154
|
+
expected = true;
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
} else if (_.type(val) === 'object') {
|
|
159
|
+
if (!flag(this, 'negate')) {
|
|
160
|
+
for (var k in val) new Assertion(obj).property(k, val[k]);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
var subset = {}
|
|
164
|
+
for (var k in val) subset[k] = obj[k]
|
|
165
|
+
expected = _.eql(subset, val);
|
|
166
|
+
} else {
|
|
167
|
+
expected = obj && ~obj.indexOf(val)
|
|
168
|
+
}
|
|
149
169
|
this.assert(
|
|
150
|
-
|
|
170
|
+
expected
|
|
151
171
|
, 'expected #{this} to include ' + _.inspect(val)
|
|
152
172
|
, 'expected #{this} to not include ' + _.inspect(val));
|
|
153
173
|
}
|
|
@@ -851,7 +871,7 @@ module.exports = function (chai, _) {
|
|
|
851
871
|
}
|
|
852
872
|
|
|
853
873
|
Assertion.addChainableMethod('length', assertLength, assertLengthChain);
|
|
854
|
-
Assertion.addMethod('lengthOf', assertLength
|
|
874
|
+
Assertion.addMethod('lengthOf', assertLength);
|
|
855
875
|
|
|
856
876
|
/**
|
|
857
877
|
* ### .match(regexp)
|
|
@@ -930,6 +950,7 @@ module.exports = function (chai, _) {
|
|
|
930
950
|
if (!keys.length) throw new Error('keys required');
|
|
931
951
|
|
|
932
952
|
var actual = Object.keys(obj)
|
|
953
|
+
, expected = keys
|
|
933
954
|
, len = keys.length;
|
|
934
955
|
|
|
935
956
|
// Inclusion
|
|
@@ -964,6 +985,9 @@ module.exports = function (chai, _) {
|
|
|
964
985
|
ok
|
|
965
986
|
, 'expected #{this} to ' + str
|
|
966
987
|
, 'expected #{this} to not ' + str
|
|
988
|
+
, expected.sort()
|
|
989
|
+
, actual.sort()
|
|
990
|
+
, true
|
|
967
991
|
);
|
|
968
992
|
}
|
|
969
993
|
|
|
@@ -1002,6 +1026,7 @@ module.exports = function (chai, _) {
|
|
|
1002
1026
|
* @param {String|RegExp} expected error message
|
|
1003
1027
|
* @param {String} message _optional_
|
|
1004
1028
|
* @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
|
|
1029
|
+
* @returns error for chaining (null if no error)
|
|
1005
1030
|
* @api public
|
|
1006
1031
|
*/
|
|
1007
1032
|
|
|
@@ -1026,7 +1051,10 @@ module.exports = function (chai, _) {
|
|
|
1026
1051
|
constructor = null;
|
|
1027
1052
|
errMsg = null;
|
|
1028
1053
|
} else if (typeof constructor === 'function') {
|
|
1029
|
-
name =
|
|
1054
|
+
name = constructor.prototype.name || constructor.name;
|
|
1055
|
+
if (name === 'Error' && constructor !== Error) {
|
|
1056
|
+
name = (new constructor()).name;
|
|
1057
|
+
}
|
|
1030
1058
|
} else {
|
|
1031
1059
|
constructor = null;
|
|
1032
1060
|
}
|
|
@@ -1040,12 +1068,14 @@ module.exports = function (chai, _) {
|
|
|
1040
1068
|
err === desiredError
|
|
1041
1069
|
, 'expected #{this} to throw #{exp} but #{act} was thrown'
|
|
1042
1070
|
, 'expected #{this} to not throw #{exp}'
|
|
1043
|
-
, desiredError
|
|
1044
|
-
, err
|
|
1071
|
+
, (desiredError instanceof Error ? desiredError.toString() : desiredError)
|
|
1072
|
+
, (err instanceof Error ? err.toString() : err)
|
|
1045
1073
|
);
|
|
1046
1074
|
|
|
1075
|
+
flag(this, 'object', err);
|
|
1047
1076
|
return this;
|
|
1048
1077
|
}
|
|
1078
|
+
|
|
1049
1079
|
// next, check constructor
|
|
1050
1080
|
if (constructor) {
|
|
1051
1081
|
this.assert(
|
|
@@ -1053,11 +1083,15 @@ module.exports = function (chai, _) {
|
|
|
1053
1083
|
, 'expected #{this} to throw #{exp} but #{act} was thrown'
|
|
1054
1084
|
, 'expected #{this} to not throw #{exp} but #{act} was thrown'
|
|
1055
1085
|
, name
|
|
1056
|
-
, err
|
|
1086
|
+
, (err instanceof Error ? err.toString() : err)
|
|
1057
1087
|
);
|
|
1058
1088
|
|
|
1059
|
-
if (!errMsg)
|
|
1089
|
+
if (!errMsg) {
|
|
1090
|
+
flag(this, 'object', err);
|
|
1091
|
+
return this;
|
|
1092
|
+
}
|
|
1060
1093
|
}
|
|
1094
|
+
|
|
1061
1095
|
// next, check message
|
|
1062
1096
|
var message = 'object' === _.type(err) && "message" in err
|
|
1063
1097
|
? err.message
|
|
@@ -1072,6 +1106,7 @@ module.exports = function (chai, _) {
|
|
|
1072
1106
|
, message
|
|
1073
1107
|
);
|
|
1074
1108
|
|
|
1109
|
+
flag(this, 'object', err);
|
|
1075
1110
|
return this;
|
|
1076
1111
|
} else if ((message != null) && errMsg && 'string' === typeof errMsg) {
|
|
1077
1112
|
this.assert(
|
|
@@ -1082,6 +1117,7 @@ module.exports = function (chai, _) {
|
|
|
1082
1117
|
, message
|
|
1083
1118
|
);
|
|
1084
1119
|
|
|
1120
|
+
flag(this, 'object', err);
|
|
1085
1121
|
return this;
|
|
1086
1122
|
} else {
|
|
1087
1123
|
thrown = true;
|
|
@@ -1104,9 +1140,11 @@ module.exports = function (chai, _) {
|
|
|
1104
1140
|
thrown === true
|
|
1105
1141
|
, 'expected #{this} to throw ' + expectedThrown + actuallyGot
|
|
1106
1142
|
, 'expected #{this} to not throw ' + expectedThrown + actuallyGot
|
|
1107
|
-
, desiredError
|
|
1108
|
-
, thrownError
|
|
1143
|
+
, (desiredError instanceof Error ? desiredError.toString() : desiredError)
|
|
1144
|
+
, (thrownError instanceof Error ? thrownError.toString() : thrownError)
|
|
1109
1145
|
);
|
|
1146
|
+
|
|
1147
|
+
flag(this, 'object', thrownError);
|
|
1110
1148
|
};
|
|
1111
1149
|
|
|
1112
1150
|
Assertion.addMethod('throw', assertThrows);
|
|
@@ -1185,12 +1223,13 @@ module.exports = function (chai, _) {
|
|
|
1185
1223
|
Assertion.addMethod('satisfy', function (matcher, msg) {
|
|
1186
1224
|
if (msg) flag(this, 'message', msg);
|
|
1187
1225
|
var obj = flag(this, 'object');
|
|
1226
|
+
var result = matcher(obj);
|
|
1188
1227
|
this.assert(
|
|
1189
|
-
|
|
1228
|
+
result
|
|
1190
1229
|
, 'expected #{this} to satisfy ' + _.objDisplay(matcher)
|
|
1191
1230
|
, 'expected #{this} to not satisfy' + _.objDisplay(matcher)
|
|
1192
1231
|
, this.negate ? false : true
|
|
1193
|
-
,
|
|
1232
|
+
, result
|
|
1194
1233
|
);
|
|
1195
1234
|
});
|
|
1196
1235
|
|
|
@@ -1211,6 +1250,12 @@ module.exports = function (chai, _) {
|
|
|
1211
1250
|
Assertion.addMethod('closeTo', function (expected, delta, msg) {
|
|
1212
1251
|
if (msg) flag(this, 'message', msg);
|
|
1213
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
|
+
|
|
1214
1259
|
this.assert(
|
|
1215
1260
|
Math.abs(obj - expected) <= delta
|
|
1216
1261
|
, 'expected #{this} to be close to ' + expected + ' +/- ' + delta
|
|
@@ -1218,9 +1263,13 @@ module.exports = function (chai, _) {
|
|
|
1218
1263
|
);
|
|
1219
1264
|
});
|
|
1220
1265
|
|
|
1221
|
-
function isSubsetOf(subset, superset) {
|
|
1266
|
+
function isSubsetOf(subset, superset, cmp) {
|
|
1222
1267
|
return subset.every(function(elem) {
|
|
1223
|
-
return superset.indexOf(elem) !== -1;
|
|
1268
|
+
if (!cmp) return superset.indexOf(elem) !== -1;
|
|
1269
|
+
|
|
1270
|
+
return superset.some(function(elem2) {
|
|
1271
|
+
return cmp(elem, elem2);
|
|
1272
|
+
});
|
|
1224
1273
|
})
|
|
1225
1274
|
}
|
|
1226
1275
|
|
|
@@ -1228,7 +1277,9 @@ module.exports = function (chai, _) {
|
|
|
1228
1277
|
* ### .members(set)
|
|
1229
1278
|
*
|
|
1230
1279
|
* Asserts that the target is a superset of `set`,
|
|
1231
|
-
* or that the target and `set` have the same members.
|
|
1280
|
+
* or that the target and `set` have the same strictly-equal (===) members.
|
|
1281
|
+
* Alternately, if the `deep` flag is set, set members are compared for deep
|
|
1282
|
+
* equality.
|
|
1232
1283
|
*
|
|
1233
1284
|
* expect([1, 2, 3]).to.include.members([3, 2]);
|
|
1234
1285
|
* expect([1, 2, 3]).to.not.include.members([3, 2, 8]);
|
|
@@ -1236,6 +1287,8 @@ module.exports = function (chai, _) {
|
|
|
1236
1287
|
* expect([4, 2]).to.have.members([2, 4]);
|
|
1237
1288
|
* expect([5, 2]).to.not.have.members([5, 2, 1]);
|
|
1238
1289
|
*
|
|
1290
|
+
* expect([{ id: 1 }]).to.deep.include.members([{ id: 1 }]);
|
|
1291
|
+
*
|
|
1239
1292
|
* @name members
|
|
1240
1293
|
* @param {Array} set
|
|
1241
1294
|
* @param {String} message _optional_
|
|
@@ -1249,9 +1302,11 @@ module.exports = function (chai, _) {
|
|
|
1249
1302
|
new Assertion(obj).to.be.an('array');
|
|
1250
1303
|
new Assertion(subset).to.be.an('array');
|
|
1251
1304
|
|
|
1305
|
+
var cmp = flag(this, 'deep') ? _.eql : undefined;
|
|
1306
|
+
|
|
1252
1307
|
if (flag(this, 'contains')) {
|
|
1253
1308
|
return this.assert(
|
|
1254
|
-
isSubsetOf(subset, obj)
|
|
1309
|
+
isSubsetOf(subset, obj, cmp)
|
|
1255
1310
|
, 'expected #{this} to be a superset of #{act}'
|
|
1256
1311
|
, 'expected #{this} to not be a superset of #{act}'
|
|
1257
1312
|
, obj
|
|
@@ -1260,7 +1315,7 @@ module.exports = function (chai, _) {
|
|
|
1260
1315
|
}
|
|
1261
1316
|
|
|
1262
1317
|
this.assert(
|
|
1263
|
-
isSubsetOf(obj, subset) && isSubsetOf(subset, obj)
|
|
1318
|
+
isSubsetOf(obj, subset, cmp) && isSubsetOf(subset, obj, cmp)
|
|
1264
1319
|
, 'expected #{this} to have the same members as #{act}'
|
|
1265
1320
|
, 'expected #{this} to not have the same members as #{act}'
|
|
1266
1321
|
, obj
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* chai
|
|
3
|
-
* Copyright(c) 2011-
|
|
3
|
+
* Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
|
|
4
4
|
* MIT Licensed
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -33,7 +33,7 @@ module.exports = function (chai, util) {
|
|
|
33
33
|
*/
|
|
34
34
|
|
|
35
35
|
var assert = chai.assert = function (express, errmsg) {
|
|
36
|
-
var test = new Assertion(null);
|
|
36
|
+
var test = new Assertion(null, null, chai.assert);
|
|
37
37
|
test.assert(
|
|
38
38
|
express
|
|
39
39
|
, errmsg
|
|
@@ -55,13 +55,12 @@ module.exports = function (chai, util) {
|
|
|
55
55
|
*/
|
|
56
56
|
|
|
57
57
|
assert.fail = function (actual, expected, message, operator) {
|
|
58
|
-
|
|
58
|
+
message = message || 'assert.fail()';
|
|
59
|
+
throw new chai.AssertionError(message, {
|
|
59
60
|
actual: actual
|
|
60
61
|
, expected: expected
|
|
61
|
-
, message: message
|
|
62
62
|
, operator: operator
|
|
63
|
-
|
|
64
|
-
});
|
|
63
|
+
}, assert.fail);
|
|
65
64
|
};
|
|
66
65
|
|
|
67
66
|
/**
|
|
@@ -115,7 +114,7 @@ module.exports = function (chai, util) {
|
|
|
115
114
|
*/
|
|
116
115
|
|
|
117
116
|
assert.equal = function (act, exp, msg) {
|
|
118
|
-
var test = new Assertion(act, msg);
|
|
117
|
+
var test = new Assertion(act, msg, assert.equal);
|
|
119
118
|
|
|
120
119
|
test.assert(
|
|
121
120
|
exp == flag(test, 'object')
|
|
@@ -141,7 +140,7 @@ module.exports = function (chai, util) {
|
|
|
141
140
|
*/
|
|
142
141
|
|
|
143
142
|
assert.notEqual = function (act, exp, msg) {
|
|
144
|
-
var test = new Assertion(act, msg);
|
|
143
|
+
var test = new Assertion(act, msg, assert.notEqual);
|
|
145
144
|
|
|
146
145
|
test.assert(
|
|
147
146
|
exp != flag(test, 'object')
|
|
@@ -392,8 +391,8 @@ module.exports = function (chai, util) {
|
|
|
392
391
|
* Asserts that `value` is _not_ an object.
|
|
393
392
|
*
|
|
394
393
|
* var selection = 'chai'
|
|
395
|
-
* assert.
|
|
396
|
-
* assert.
|
|
394
|
+
* assert.isNotObject(selection, 'tea selection is not an object');
|
|
395
|
+
* assert.isNotObject(null, 'null is not an object');
|
|
397
396
|
*
|
|
398
397
|
* @name isNotObject
|
|
399
398
|
* @param {Mixed} value
|
|
@@ -657,19 +656,7 @@ module.exports = function (chai, util) {
|
|
|
657
656
|
*/
|
|
658
657
|
|
|
659
658
|
assert.include = function (exp, inc, msg) {
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
if (Array.isArray(exp)) {
|
|
663
|
-
obj.to.include(inc);
|
|
664
|
-
} else if ('string' === typeof exp) {
|
|
665
|
-
obj.to.contain.string(inc);
|
|
666
|
-
} else {
|
|
667
|
-
throw new chai.AssertionError(
|
|
668
|
-
'expected an array or string'
|
|
669
|
-
, null
|
|
670
|
-
, assert.include
|
|
671
|
-
);
|
|
672
|
-
}
|
|
659
|
+
new Assertion(exp, msg, assert.include).include(inc);
|
|
673
660
|
};
|
|
674
661
|
|
|
675
662
|
/**
|
|
@@ -689,19 +676,7 @@ module.exports = function (chai, util) {
|
|
|
689
676
|
*/
|
|
690
677
|
|
|
691
678
|
assert.notInclude = function (exp, inc, msg) {
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
if (Array.isArray(exp)) {
|
|
695
|
-
obj.to.not.include(inc);
|
|
696
|
-
} else if ('string' === typeof exp) {
|
|
697
|
-
obj.to.not.contain.string(inc);
|
|
698
|
-
} else {
|
|
699
|
-
throw new chai.AssertionError(
|
|
700
|
-
'expected an array or string'
|
|
701
|
-
, null
|
|
702
|
-
, assert.notInclude
|
|
703
|
-
);
|
|
704
|
-
}
|
|
679
|
+
new Assertion(exp, msg, assert.notInclude).not.include(inc);
|
|
705
680
|
};
|
|
706
681
|
|
|
707
682
|
/**
|
|
@@ -945,7 +920,8 @@ module.exports = function (chai, util) {
|
|
|
945
920
|
errt = null;
|
|
946
921
|
}
|
|
947
922
|
|
|
948
|
-
new Assertion(fn, msg).to.Throw(errt, errs);
|
|
923
|
+
var assertErr = new Assertion(fn, msg).to.Throw(errt, errs);
|
|
924
|
+
return flag(assertErr, 'object');
|
|
949
925
|
};
|
|
950
926
|
|
|
951
927
|
/**
|
|
@@ -1030,8 +1006,8 @@ module.exports = function (chai, util) {
|
|
|
1030
1006
|
* assert.sameMembers([ 1, 2, 3 ], [ 2, 1, 3 ], 'same members');
|
|
1031
1007
|
*
|
|
1032
1008
|
* @name sameMembers
|
|
1033
|
-
* @param {Array}
|
|
1034
|
-
* @param {Array}
|
|
1009
|
+
* @param {Array} set1
|
|
1010
|
+
* @param {Array} set2
|
|
1035
1011
|
* @param {String} message
|
|
1036
1012
|
* @api public
|
|
1037
1013
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* chai
|
|
3
|
-
* Copyright(c) 2011-
|
|
3
|
+
* Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
|
|
4
4
|
* MIT Licensed
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -8,31 +8,33 @@ module.exports = function (chai, util) {
|
|
|
8
8
|
var Assertion = chai.Assertion;
|
|
9
9
|
|
|
10
10
|
function loadShould () {
|
|
11
|
+
// explicitly define this method as function as to have it's name to include as `ssfi`
|
|
12
|
+
function shouldGetter() {
|
|
13
|
+
if (this instanceof String || this instanceof Number) {
|
|
14
|
+
return new Assertion(this.constructor(this), null, shouldGetter);
|
|
15
|
+
} else if (this instanceof Boolean) {
|
|
16
|
+
return new Assertion(this == true, null, shouldGetter);
|
|
17
|
+
}
|
|
18
|
+
return new Assertion(this, null, shouldGetter);
|
|
19
|
+
}
|
|
20
|
+
function shouldSetter(value) {
|
|
21
|
+
// See https://github.com/chaijs/chai/issues/86: this makes
|
|
22
|
+
// `whatever.should = someValue` actually set `someValue`, which is
|
|
23
|
+
// especially useful for `global.should = require('chai').should()`.
|
|
24
|
+
//
|
|
25
|
+
// Note that we have to use [[DefineProperty]] instead of [[Put]]
|
|
26
|
+
// since otherwise we would trigger this very setter!
|
|
27
|
+
Object.defineProperty(this, 'should', {
|
|
28
|
+
value: value,
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true
|
|
32
|
+
});
|
|
33
|
+
}
|
|
11
34
|
// modify Object.prototype to have `should`
|
|
12
|
-
Object.defineProperty(Object.prototype, 'should',
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
// See https://github.com/chaijs/chai/issues/86: this makes
|
|
16
|
-
// `whatever.should = someValue` actually set `someValue`, which is
|
|
17
|
-
// especially useful for `global.should = require('chai').should()`.
|
|
18
|
-
//
|
|
19
|
-
// Note that we have to use [[DefineProperty]] instead of [[Put]]
|
|
20
|
-
// since otherwise we would trigger this very setter!
|
|
21
|
-
Object.defineProperty(this, 'should', {
|
|
22
|
-
value: value,
|
|
23
|
-
enumerable: true,
|
|
24
|
-
configurable: true,
|
|
25
|
-
writable: true
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
, get: function(){
|
|
29
|
-
if (this instanceof String || this instanceof Number) {
|
|
30
|
-
return new Assertion(this.constructor(this));
|
|
31
|
-
} else if (this instanceof Boolean) {
|
|
32
|
-
return new Assertion(this == true);
|
|
33
|
-
}
|
|
34
|
-
return new Assertion(this);
|
|
35
|
-
}
|
|
35
|
+
Object.defineProperty(Object.prototype, 'should', {
|
|
36
|
+
set: shouldSetter
|
|
37
|
+
, get: shouldGetter
|
|
36
38
|
, configurable: true
|
|
37
39
|
});
|
|
38
40
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* Chai - addChainingMethod utility
|
|
3
|
-
* Copyright(c) 2012-
|
|
3
|
+
* Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
|
|
4
4
|
* MIT Licensed
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
var transferFlags = require('./transferFlags');
|
|
12
|
+
var flag = require('./flag');
|
|
13
|
+
var config = require('../config');
|
|
12
14
|
|
|
13
15
|
/*!
|
|
14
16
|
* Module variables
|
|
@@ -55,15 +57,30 @@ var call = Function.prototype.call,
|
|
|
55
57
|
*/
|
|
56
58
|
|
|
57
59
|
module.exports = function (ctx, name, method, chainingBehavior) {
|
|
58
|
-
if (typeof chainingBehavior !== 'function')
|
|
60
|
+
if (typeof chainingBehavior !== 'function') {
|
|
59
61
|
chainingBehavior = function () { };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
var chainableBehavior = {
|
|
65
|
+
method: method
|
|
66
|
+
, chainingBehavior: chainingBehavior
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// save the methods so we can overwrite them later, if we need to.
|
|
70
|
+
if (!ctx.__methods) {
|
|
71
|
+
ctx.__methods = {};
|
|
72
|
+
}
|
|
73
|
+
ctx.__methods[name] = chainableBehavior;
|
|
60
74
|
|
|
61
75
|
Object.defineProperty(ctx, name,
|
|
62
76
|
{ get: function () {
|
|
63
|
-
chainingBehavior.call(this);
|
|
77
|
+
chainableBehavior.chainingBehavior.call(this);
|
|
64
78
|
|
|
65
|
-
var assert = function () {
|
|
66
|
-
var
|
|
79
|
+
var assert = function assert() {
|
|
80
|
+
var old_ssfi = flag(this, 'ssfi');
|
|
81
|
+
if (old_ssfi && config.includeStack === false)
|
|
82
|
+
flag(this, 'ssfi', assert);
|
|
83
|
+
var result = chainableBehavior.method.apply(this, arguments);
|
|
67
84
|
return result === undefined ? this : result;
|
|
68
85
|
};
|
|
69
86
|
|