chai 4.0.2 → 4.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.
- package/CODEOWNERS +1 -0
- package/CONTRIBUTING.md +2 -2
- package/LICENSE +1 -1
- package/README.md +4 -4
- package/chai.js +684 -813
- package/lib/chai/config.js +1 -1
- package/lib/chai/core/assertions.js +404 -207
- package/lib/chai/interface/assert.js +73 -58
- package/lib/chai/interface/expect.js +13 -0
- package/lib/chai/interface/should.js +14 -0
- package/lib/chai/utils/addLengthGuard.js +0 -2
- package/lib/chai/utils/addProperty.js +1 -1
- package/lib/chai/utils/compareByInspect.js +2 -2
- package/lib/chai/utils/expectTypes.js +3 -4
- package/lib/chai/utils/getMessage.js +1 -2
- package/lib/chai/utils/getOwnEnumerableProperties.js +1 -1
- package/lib/chai/utils/inspect.js +2 -9
- package/lib/chai/utils/isProxyEnabled.js +1 -1
- package/lib/chai/utils/objDisplay.js +1 -1
- package/lib/chai/utils/overwriteChainableMethod.js +1 -1
- package/lib/chai/utils/overwriteMethod.js +1 -1
- package/lib/chai/utils/overwriteProperty.js +1 -1
- package/lib/chai/utils/proxify.js +54 -32
- package/lib/chai/utils/test.js +1 -1
- package/lib/chai/utils/transferFlags.js +1 -1
- package/lib/chai.js +1 -1
- package/package.json +11 -10
- package/sauce.browsers.js +0 -9
- package/.npmignore +0 -14
|
@@ -4,9 +4,7 @@
|
|
|
4
4
|
* MIT Licensed
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
8
7
|
module.exports = function (chai, util) {
|
|
9
|
-
|
|
10
8
|
/*!
|
|
11
9
|
* Chai dependencies.
|
|
12
10
|
*/
|
|
@@ -43,10 +41,18 @@ module.exports = function (chai, util) {
|
|
|
43
41
|
};
|
|
44
42
|
|
|
45
43
|
/**
|
|
44
|
+
* ### .fail([message])
|
|
46
45
|
* ### .fail(actual, expected, [message], [operator])
|
|
47
46
|
*
|
|
48
47
|
* Throw a failure. Node.js `assert` module-compatible.
|
|
49
48
|
*
|
|
49
|
+
* assert.fail();
|
|
50
|
+
* assert.fail("custom error message");
|
|
51
|
+
* assert.fail(1, 2);
|
|
52
|
+
* assert.fail(1, 2, "custom error message");
|
|
53
|
+
* assert.fail(1, 2, "custom error message", ">");
|
|
54
|
+
* assert.fail(1, 2, undefined, ">");
|
|
55
|
+
*
|
|
50
56
|
* @name fail
|
|
51
57
|
* @param {Mixed} actual
|
|
52
58
|
* @param {Mixed} expected
|
|
@@ -57,6 +63,13 @@ module.exports = function (chai, util) {
|
|
|
57
63
|
*/
|
|
58
64
|
|
|
59
65
|
assert.fail = function (actual, expected, message, operator) {
|
|
66
|
+
if (arguments.length < 2) {
|
|
67
|
+
// Comply with Node's fail([message]) interface
|
|
68
|
+
|
|
69
|
+
message = actual;
|
|
70
|
+
actual = undefined;
|
|
71
|
+
}
|
|
72
|
+
|
|
60
73
|
message = message || 'assert.fail()';
|
|
61
74
|
throw new chai.AssertionError(message, {
|
|
62
75
|
actual: actual
|
|
@@ -906,7 +919,7 @@ module.exports = function (chai, util) {
|
|
|
906
919
|
* an array, the array is searched for an element that's strictly equal to the
|
|
907
920
|
* given value. When asserting a subset of properties in an object, the object
|
|
908
921
|
* is searched for the given property keys, checking that each one is present
|
|
909
|
-
* and
|
|
922
|
+
* and strictly equal to the given property value. For instance:
|
|
910
923
|
*
|
|
911
924
|
* var obj1 = {a: 1}
|
|
912
925
|
* , obj2 = {b: 2};
|
|
@@ -933,8 +946,8 @@ module.exports = function (chai, util) {
|
|
|
933
946
|
* the absence of a value in an array, a substring in a string, or a subset of
|
|
934
947
|
* properties in an object.
|
|
935
948
|
*
|
|
936
|
-
* assert.notInclude([1,2,3], 4,
|
|
937
|
-
* assert.notInclude('foobar', 'baz',
|
|
949
|
+
* assert.notInclude([1,2,3], 4, "array doesn't contain value");
|
|
950
|
+
* assert.notInclude('foobar', 'baz', "string doesn't contain substring");
|
|
938
951
|
* assert.notInclude({ foo: 'bar', hello: 'universe' }, { foo: 'baz' }, 'object doesn't contain property');
|
|
939
952
|
*
|
|
940
953
|
* Strict equality (===) is used. When asserting the absence of a value in an
|
|
@@ -1014,24 +1027,24 @@ module.exports = function (chai, util) {
|
|
|
1014
1027
|
|
|
1015
1028
|
/**
|
|
1016
1029
|
* ### .nestedInclude(haystack, needle, [message])
|
|
1017
|
-
*
|
|
1018
|
-
* Asserts that 'haystack' includes 'needle'.
|
|
1019
|
-
* Can be used to assert the inclusion of a subset of properties in an
|
|
1030
|
+
*
|
|
1031
|
+
* Asserts that 'haystack' includes 'needle'.
|
|
1032
|
+
* Can be used to assert the inclusion of a subset of properties in an
|
|
1020
1033
|
* object.
|
|
1021
|
-
* Enables the use of dot- and bracket-notation for referencing nested
|
|
1034
|
+
* Enables the use of dot- and bracket-notation for referencing nested
|
|
1022
1035
|
* properties.
|
|
1023
1036
|
* '[]' and '.' in property names can be escaped using double backslashes.
|
|
1024
|
-
*
|
|
1037
|
+
*
|
|
1025
1038
|
* assert.nestedInclude({'.a': {'b': 'x'}}, {'\\.a.[b]': 'x'});
|
|
1026
1039
|
* assert.nestedInclude({'a': {'[b]': 'x'}}, {'a.\\[b\\]': 'x'});
|
|
1027
|
-
*
|
|
1040
|
+
*
|
|
1028
1041
|
* @name nestedInclude
|
|
1029
1042
|
* @param {Object} haystack
|
|
1030
1043
|
* @param {Object} needle
|
|
1031
1044
|
* @param {String} message
|
|
1032
1045
|
* @namespace Assert
|
|
1033
|
-
* @api public
|
|
1034
|
-
*/
|
|
1046
|
+
* @api public
|
|
1047
|
+
*/
|
|
1035
1048
|
|
|
1036
1049
|
assert.nestedInclude = function (exp, inc, msg) {
|
|
1037
1050
|
new Assertion(exp, msg, assert.nestedInclude, true).nested.include(inc);
|
|
@@ -1039,24 +1052,24 @@ module.exports = function (chai, util) {
|
|
|
1039
1052
|
|
|
1040
1053
|
/**
|
|
1041
1054
|
* ### .notNestedInclude(haystack, needle, [message])
|
|
1042
|
-
*
|
|
1043
|
-
* Asserts that 'haystack' does not include 'needle'.
|
|
1044
|
-
* Can be used to assert the absence of a subset of properties in an
|
|
1055
|
+
*
|
|
1056
|
+
* Asserts that 'haystack' does not include 'needle'.
|
|
1057
|
+
* Can be used to assert the absence of a subset of properties in an
|
|
1045
1058
|
* object.
|
|
1046
|
-
* Enables the use of dot- and bracket-notation for referencing nested
|
|
1047
|
-
* properties.
|
|
1059
|
+
* Enables the use of dot- and bracket-notation for referencing nested
|
|
1060
|
+
* properties.
|
|
1048
1061
|
* '[]' and '.' in property names can be escaped using double backslashes.
|
|
1049
|
-
*
|
|
1062
|
+
*
|
|
1050
1063
|
* assert.notNestedInclude({'.a': {'b': 'x'}}, {'\\.a.b': 'y'});
|
|
1051
1064
|
* assert.notNestedInclude({'a': {'[b]': 'x'}}, {'a.\\[b\\]': 'y'});
|
|
1052
|
-
*
|
|
1065
|
+
*
|
|
1053
1066
|
* @name notNestedInclude
|
|
1054
1067
|
* @param {Object} haystack
|
|
1055
1068
|
* @param {Object} needle
|
|
1056
1069
|
* @param {String} message
|
|
1057
1070
|
* @namespace Assert
|
|
1058
|
-
* @api public
|
|
1059
|
-
*/
|
|
1071
|
+
* @api public
|
|
1072
|
+
*/
|
|
1060
1073
|
|
|
1061
1074
|
assert.notNestedInclude = function (exp, inc, msg) {
|
|
1062
1075
|
new Assertion(exp, msg, assert.notNestedInclude, true)
|
|
@@ -1065,23 +1078,23 @@ module.exports = function (chai, util) {
|
|
|
1065
1078
|
|
|
1066
1079
|
/**
|
|
1067
1080
|
* ### .deepNestedInclude(haystack, needle, [message])
|
|
1068
|
-
*
|
|
1081
|
+
*
|
|
1069
1082
|
* Asserts that 'haystack' includes 'needle'.
|
|
1070
|
-
* Can be used to assert the inclusion of a subset of properties in an
|
|
1083
|
+
* Can be used to assert the inclusion of a subset of properties in an
|
|
1071
1084
|
* object while checking for deep equality.
|
|
1072
|
-
* Enables the use of dot- and bracket-notation for referencing nested
|
|
1085
|
+
* Enables the use of dot- and bracket-notation for referencing nested
|
|
1073
1086
|
* properties.
|
|
1074
1087
|
* '[]' and '.' in property names can be escaped using double backslashes.
|
|
1075
|
-
*
|
|
1088
|
+
*
|
|
1076
1089
|
* assert.deepNestedInclude({a: {b: [{x: 1}]}}, {'a.b[0]': {x: 1}});
|
|
1077
1090
|
* assert.deepNestedInclude({'.a': {'[b]': {x: 1}}}, {'\\.a.\\[b\\]': {x: 1}});
|
|
1078
|
-
*
|
|
1091
|
+
*
|
|
1079
1092
|
* @name deepNestedInclude
|
|
1080
1093
|
* @param {Object} haystack
|
|
1081
1094
|
* @param {Object} needle
|
|
1082
1095
|
* @param {String} message
|
|
1083
1096
|
* @namespace Assert
|
|
1084
|
-
* @api public
|
|
1097
|
+
* @api public
|
|
1085
1098
|
*/
|
|
1086
1099
|
|
|
1087
1100
|
assert.deepNestedInclude = function(exp, inc, msg) {
|
|
@@ -1091,23 +1104,23 @@ module.exports = function (chai, util) {
|
|
|
1091
1104
|
|
|
1092
1105
|
/**
|
|
1093
1106
|
* ### .notDeepNestedInclude(haystack, needle, [message])
|
|
1094
|
-
*
|
|
1107
|
+
*
|
|
1095
1108
|
* Asserts that 'haystack' does not include 'needle'.
|
|
1096
|
-
* Can be used to assert the absence of a subset of properties in an
|
|
1109
|
+
* Can be used to assert the absence of a subset of properties in an
|
|
1097
1110
|
* object while checking for deep equality.
|
|
1098
|
-
* Enables the use of dot- and bracket-notation for referencing nested
|
|
1111
|
+
* Enables the use of dot- and bracket-notation for referencing nested
|
|
1099
1112
|
* properties.
|
|
1100
1113
|
* '[]' and '.' in property names can be escaped using double backslashes.
|
|
1101
|
-
*
|
|
1114
|
+
*
|
|
1102
1115
|
* assert.notDeepNestedInclude({a: {b: [{x: 1}]}}, {'a.b[0]': {y: 1}})
|
|
1103
1116
|
* assert.notDeepNestedInclude({'.a': {'[b]': {x: 1}}}, {'\\.a.\\[b\\]': {y: 2}});
|
|
1104
|
-
*
|
|
1117
|
+
*
|
|
1105
1118
|
* @name notDeepNestedInclude
|
|
1106
1119
|
* @param {Object} haystack
|
|
1107
1120
|
* @param {Object} needle
|
|
1108
1121
|
* @param {String} message
|
|
1109
1122
|
* @namespace Assert
|
|
1110
|
-
* @api public
|
|
1123
|
+
* @api public
|
|
1111
1124
|
*/
|
|
1112
1125
|
|
|
1113
1126
|
assert.notDeepNestedInclude = function(exp, inc, msg) {
|
|
@@ -1117,13 +1130,13 @@ module.exports = function (chai, util) {
|
|
|
1117
1130
|
|
|
1118
1131
|
/**
|
|
1119
1132
|
* ### .ownInclude(haystack, needle, [message])
|
|
1120
|
-
*
|
|
1133
|
+
*
|
|
1121
1134
|
* Asserts that 'haystack' includes 'needle'.
|
|
1122
|
-
* Can be used to assert the inclusion of a subset of properties in an
|
|
1135
|
+
* Can be used to assert the inclusion of a subset of properties in an
|
|
1123
1136
|
* object while ignoring inherited properties.
|
|
1124
|
-
*
|
|
1137
|
+
*
|
|
1125
1138
|
* assert.ownInclude({ a: 1 }, { a: 1 });
|
|
1126
|
-
*
|
|
1139
|
+
*
|
|
1127
1140
|
* @name ownInclude
|
|
1128
1141
|
* @param {Object} haystack
|
|
1129
1142
|
* @param {Object} needle
|
|
@@ -1138,15 +1151,15 @@ module.exports = function (chai, util) {
|
|
|
1138
1151
|
|
|
1139
1152
|
/**
|
|
1140
1153
|
* ### .notOwnInclude(haystack, needle, [message])
|
|
1141
|
-
*
|
|
1154
|
+
*
|
|
1142
1155
|
* Asserts that 'haystack' includes 'needle'.
|
|
1143
|
-
* Can be used to assert the absence of a subset of properties in an
|
|
1156
|
+
* Can be used to assert the absence of a subset of properties in an
|
|
1144
1157
|
* object while ignoring inherited properties.
|
|
1145
|
-
*
|
|
1158
|
+
*
|
|
1146
1159
|
* Object.prototype.b = 2;
|
|
1147
|
-
*
|
|
1160
|
+
*
|
|
1148
1161
|
* assert.notOwnInclude({ a: 1 }, { b: 2 });
|
|
1149
|
-
*
|
|
1162
|
+
*
|
|
1150
1163
|
* @name notOwnInclude
|
|
1151
1164
|
* @param {Object} haystack
|
|
1152
1165
|
* @param {Object} needle
|
|
@@ -1161,13 +1174,13 @@ module.exports = function (chai, util) {
|
|
|
1161
1174
|
|
|
1162
1175
|
/**
|
|
1163
1176
|
* ### .deepOwnInclude(haystack, needle, [message])
|
|
1164
|
-
*
|
|
1177
|
+
*
|
|
1165
1178
|
* Asserts that 'haystack' includes 'needle'.
|
|
1166
|
-
* Can be used to assert the inclusion of a subset of properties in an
|
|
1179
|
+
* Can be used to assert the inclusion of a subset of properties in an
|
|
1167
1180
|
* object while ignoring inherited properties and checking for deep equality.
|
|
1168
|
-
*
|
|
1181
|
+
*
|
|
1169
1182
|
* assert.deepOwnInclude({a: {b: 2}}, {a: {b: 2}});
|
|
1170
|
-
*
|
|
1183
|
+
*
|
|
1171
1184
|
* @name deepOwnInclude
|
|
1172
1185
|
* @param {Object} haystack
|
|
1173
1186
|
* @param {Object} needle
|
|
@@ -1183,13 +1196,13 @@ module.exports = function (chai, util) {
|
|
|
1183
1196
|
|
|
1184
1197
|
/**
|
|
1185
1198
|
* ### .notDeepOwnInclude(haystack, needle, [message])
|
|
1186
|
-
*
|
|
1199
|
+
*
|
|
1187
1200
|
* Asserts that 'haystack' includes 'needle'.
|
|
1188
|
-
* Can be used to assert the absence of a subset of properties in an
|
|
1201
|
+
* Can be used to assert the absence of a subset of properties in an
|
|
1189
1202
|
* object while ignoring inherited properties and checking for deep equality.
|
|
1190
|
-
*
|
|
1203
|
+
*
|
|
1191
1204
|
* assert.notDeepOwnInclude({a: {b: 2}}, {a: {c: 3}});
|
|
1192
|
-
*
|
|
1205
|
+
*
|
|
1193
1206
|
* @name notDeepOwnInclude
|
|
1194
1207
|
* @param {Object} haystack
|
|
1195
1208
|
* @param {Object} needle
|
|
@@ -1651,10 +1664,12 @@ module.exports = function (chai, util) {
|
|
|
1651
1664
|
/**
|
|
1652
1665
|
* ### .lengthOf(object, length, [message])
|
|
1653
1666
|
*
|
|
1654
|
-
* Asserts that `object` has a `length`
|
|
1667
|
+
* Asserts that `object` has a `length` or `size` with the expected value.
|
|
1655
1668
|
*
|
|
1656
1669
|
* assert.lengthOf([1,2,3], 3, 'array has length of 3');
|
|
1657
1670
|
* assert.lengthOf('foobar', 6, 'string has length of 6');
|
|
1671
|
+
* assert.lengthOf(new Set([1,2,3]), 3, 'set has size of 3');
|
|
1672
|
+
* assert.lengthOf(new Map([['a',1],['b',2],['c',3]]), 3, 'map has size of 3');
|
|
1658
1673
|
*
|
|
1659
1674
|
* @name lengthOf
|
|
1660
1675
|
* @param {Mixed} object
|
|
@@ -1675,10 +1690,10 @@ module.exports = function (chai, util) {
|
|
|
1675
1690
|
* You can also provide a single object instead of a `keys` array and its keys
|
|
1676
1691
|
* will be used as the expected set of keys.
|
|
1677
1692
|
*
|
|
1678
|
-
* assert.
|
|
1679
|
-
* assert.
|
|
1680
|
-
* assert.
|
|
1681
|
-
* assert.
|
|
1693
|
+
* assert.hasAnyKeys({foo: 1, bar: 2, baz: 3}, ['foo', 'iDontExist', 'baz']);
|
|
1694
|
+
* assert.hasAnyKeys({foo: 1, bar: 2, baz: 3}, {foo: 30, iDontExist: 99, baz: 1337});
|
|
1695
|
+
* assert.hasAnyKeys(new Map([[{foo: 1}, 'bar'], ['key', 'value']]), [{foo: 1}, 'key']);
|
|
1696
|
+
* assert.hasAnyKeys(new Set([{foo: 'bar'}, 'anotherKey']), [{foo: 'bar'}, 'anotherKey']);
|
|
1682
1697
|
*
|
|
1683
1698
|
* @name hasAnyKeys
|
|
1684
1699
|
* @param {Mixed} object
|
|
@@ -1942,8 +1957,8 @@ module.exports = function (chai, util) {
|
|
|
1942
1957
|
* If `errMsgMatcher` is provided, it also asserts that the error thrown will have a
|
|
1943
1958
|
* message matching `errMsgMatcher`.
|
|
1944
1959
|
*
|
|
1945
|
-
* assert.throws(fn, '
|
|
1946
|
-
* assert.throws(fn, /
|
|
1960
|
+
* assert.throws(fn, 'Error thrown must have this msg');
|
|
1961
|
+
* assert.throws(fn, /Error thrown must have a msg that matches this/);
|
|
1947
1962
|
* assert.throws(fn, ReferenceError);
|
|
1948
1963
|
* assert.throws(fn, errorInstance);
|
|
1949
1964
|
* assert.throws(fn, ReferenceError, 'Error thrown must be a ReferenceError and have this msg');
|
|
@@ -10,10 +10,18 @@ module.exports = function (chai, util) {
|
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
+
* ### .fail([message])
|
|
13
14
|
* ### .fail(actual, expected, [message], [operator])
|
|
14
15
|
*
|
|
15
16
|
* Throw a failure.
|
|
16
17
|
*
|
|
18
|
+
* expect.fail();
|
|
19
|
+
* expect.fail("custom error message");
|
|
20
|
+
* expect.fail(1, 2);
|
|
21
|
+
* expect.fail(1, 2, "custom error message");
|
|
22
|
+
* expect.fail(1, 2, "custom error message", ">");
|
|
23
|
+
* expect.fail(1, 2, undefined, ">");
|
|
24
|
+
*
|
|
17
25
|
* @name fail
|
|
18
26
|
* @param {Mixed} actual
|
|
19
27
|
* @param {Mixed} expected
|
|
@@ -24,6 +32,11 @@ module.exports = function (chai, util) {
|
|
|
24
32
|
*/
|
|
25
33
|
|
|
26
34
|
chai.expect.fail = function (actual, expected, message, operator) {
|
|
35
|
+
if (arguments.length < 2) {
|
|
36
|
+
message = actual;
|
|
37
|
+
actual = undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
27
40
|
message = message || 'expect.fail()';
|
|
28
41
|
throw new chai.AssertionError(message, {
|
|
29
42
|
actual: actual
|
|
@@ -42,10 +42,19 @@ module.exports = function (chai, util) {
|
|
|
42
42
|
var should = {};
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
|
+
* ### .fail([message])
|
|
45
46
|
* ### .fail(actual, expected, [message], [operator])
|
|
46
47
|
*
|
|
47
48
|
* Throw a failure.
|
|
48
49
|
*
|
|
50
|
+
* should.fail();
|
|
51
|
+
* should.fail("custom error message");
|
|
52
|
+
* should.fail(1, 2);
|
|
53
|
+
* should.fail(1, 2, "custom error message");
|
|
54
|
+
* should.fail(1, 2, "custom error message", ">");
|
|
55
|
+
* should.fail(1, 2, undefined, ">");
|
|
56
|
+
*
|
|
57
|
+
*
|
|
49
58
|
* @name fail
|
|
50
59
|
* @param {Mixed} actual
|
|
51
60
|
* @param {Mixed} expected
|
|
@@ -56,6 +65,11 @@ module.exports = function (chai, util) {
|
|
|
56
65
|
*/
|
|
57
66
|
|
|
58
67
|
should.fail = function (actual, expected, message, operator) {
|
|
68
|
+
if (arguments.length < 2) {
|
|
69
|
+
message = actual;
|
|
70
|
+
actual = undefined;
|
|
71
|
+
}
|
|
72
|
+
|
|
59
73
|
message = message || 'should.fail()';
|
|
60
74
|
throw new chai.AssertionError(message, {
|
|
61
75
|
actual: actual
|
|
@@ -36,7 +36,7 @@ var transferFlags = require('./transferFlags');
|
|
|
36
36
|
*/
|
|
37
37
|
|
|
38
38
|
module.exports = function addProperty(ctx, name, getter) {
|
|
39
|
-
getter = getter === undefined ?
|
|
39
|
+
getter = getter === undefined ? function () {} : getter;
|
|
40
40
|
|
|
41
41
|
Object.defineProperty(ctx, name,
|
|
42
42
|
{ get: function propertyGetter() {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
/*!
|
|
8
|
-
* Module
|
|
8
|
+
* Module dependencies
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
var inspect = require('./inspect');
|
|
@@ -20,7 +20,7 @@ var inspect = require('./inspect');
|
|
|
20
20
|
*
|
|
21
21
|
* @param {Mixed} first element to compare
|
|
22
22
|
* @param {Mixed} second element to compare
|
|
23
|
-
* @returns {Number} -1 if 'a' should come before 'b'; otherwise 1
|
|
23
|
+
* @returns {Number} -1 if 'a' should come before 'b'; otherwise 1
|
|
24
24
|
* @name compareByInspect
|
|
25
25
|
* @namespace Utils
|
|
26
26
|
* @api public
|
|
@@ -13,8 +13,6 @@
|
|
|
13
13
|
*
|
|
14
14
|
* @param {Mixed} obj constructed Assertion
|
|
15
15
|
* @param {Array} type A list of allowed types for this assertion
|
|
16
|
-
* @param {Function} ssfi starting point for removing implementation frames from
|
|
17
|
-
* stack trace of AssertionError
|
|
18
16
|
* @namespace Utils
|
|
19
17
|
* @name expectTypes
|
|
20
18
|
* @api public
|
|
@@ -24,8 +22,9 @@ var AssertionError = require('assertion-error');
|
|
|
24
22
|
var flag = require('./flag');
|
|
25
23
|
var type = require('type-detect');
|
|
26
24
|
|
|
27
|
-
module.exports = function expectTypes(obj, types
|
|
25
|
+
module.exports = function expectTypes(obj, types) {
|
|
28
26
|
var flagMsg = flag(obj, 'message');
|
|
27
|
+
var ssfi = flag(obj, 'ssfi');
|
|
29
28
|
|
|
30
29
|
flagMsg = flagMsg ? flagMsg + ': ' : '';
|
|
31
30
|
|
|
@@ -33,7 +32,7 @@ module.exports = function expectTypes(obj, types, ssfi) {
|
|
|
33
32
|
types = types.map(function (t) { return t.toLowerCase(); });
|
|
34
33
|
types.sort();
|
|
35
34
|
|
|
36
|
-
// Transforms ['lorem', 'ipsum'] into 'a
|
|
35
|
+
// Transforms ['lorem', 'ipsum'] into 'a lorem, or an ipsum'
|
|
37
36
|
var str = types.map(function (t, index) {
|
|
38
37
|
var art = ~[ 'a', 'e', 'i', 'o', 'u' ].indexOf(t.charAt(0)) ? 'an' : 'a';
|
|
39
38
|
var or = types.length > 1 && index === types.length - 1 ? 'or ' : '';
|
|
@@ -86,7 +86,7 @@ function formatValue(ctx, value, recurseTimes) {
|
|
|
86
86
|
var container = document.createElementNS(ns, '_');
|
|
87
87
|
|
|
88
88
|
container.appendChild(value.cloneNode(false));
|
|
89
|
-
html = container.innerHTML
|
|
89
|
+
var html = container.innerHTML
|
|
90
90
|
.replace('><', '>' + value.innerHTML + '<');
|
|
91
91
|
container.innerHTML = '';
|
|
92
92
|
return html;
|
|
@@ -105,7 +105,7 @@ function formatValue(ctx, value, recurseTimes) {
|
|
|
105
105
|
|
|
106
106
|
var name, nameSuffix;
|
|
107
107
|
|
|
108
|
-
// Some type of object without properties can be
|
|
108
|
+
// Some type of object without properties can be shortcut.
|
|
109
109
|
// In IE, errors have a single `stack` property, or if they are vanilla `Error`,
|
|
110
110
|
// a `stack` plus `description` property; ignore those for consistency.
|
|
111
111
|
if (keys.length === 0 || (isError(value) && (
|
|
@@ -196,7 +196,6 @@ function formatValue(ctx, value, recurseTimes) {
|
|
|
196
196
|
return reduceToSingleString(output, base, braces);
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
-
|
|
200
199
|
function formatPrimitive(ctx, value) {
|
|
201
200
|
switch (typeof value) {
|
|
202
201
|
case 'undefined':
|
|
@@ -226,12 +225,10 @@ function formatPrimitive(ctx, value) {
|
|
|
226
225
|
}
|
|
227
226
|
}
|
|
228
227
|
|
|
229
|
-
|
|
230
228
|
function formatError(value) {
|
|
231
229
|
return '[' + Error.prototype.toString.call(value) + ']';
|
|
232
230
|
}
|
|
233
231
|
|
|
234
|
-
|
|
235
232
|
function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
|
|
236
233
|
var output = [];
|
|
237
234
|
for (var i = 0, l = value.length; i < l; ++i) {
|
|
@@ -334,12 +331,8 @@ function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
|
|
|
334
331
|
return name + ': ' + str;
|
|
335
332
|
}
|
|
336
333
|
|
|
337
|
-
|
|
338
334
|
function reduceToSingleString(output, base, braces) {
|
|
339
|
-
var numLinesEst = 0;
|
|
340
335
|
var length = output.reduce(function(prev, cur) {
|
|
341
|
-
numLinesEst++;
|
|
342
|
-
if (cur.indexOf('\n') >= 0) numLinesEst++;
|
|
343
336
|
return prev + cur.length + 1;
|
|
344
337
|
}, 0);
|
|
345
338
|
|
|
@@ -10,7 +10,7 @@ var transferFlags = require('./transferFlags');
|
|
|
10
10
|
/**
|
|
11
11
|
* ### .overwriteChainableMethod(ctx, name, method, chainingBehavior)
|
|
12
12
|
*
|
|
13
|
-
*
|
|
13
|
+
* Overwrites an already existing chainable method
|
|
14
14
|
* and provides access to the previous function or
|
|
15
15
|
* property. Must return functions to be used for
|
|
16
16
|
* name.
|
|
@@ -13,7 +13,7 @@ var transferFlags = require('./transferFlags');
|
|
|
13
13
|
/**
|
|
14
14
|
* ### .overwriteMethod(ctx, name, fn)
|
|
15
15
|
*
|
|
16
|
-
*
|
|
16
|
+
* Overwrites an already existing method and provides
|
|
17
17
|
* access to previous function. Must return function
|
|
18
18
|
* to be used for name.
|
|
19
19
|
*
|
|
@@ -12,7 +12,7 @@ var transferFlags = require('./transferFlags');
|
|
|
12
12
|
/**
|
|
13
13
|
* ### .overwriteProperty(ctx, name, fn)
|
|
14
14
|
*
|
|
15
|
-
*
|
|
15
|
+
* Overwrites an already existing property getter and provides
|
|
16
16
|
* access to previous value. Must return function to use as getter.
|
|
17
17
|
*
|
|
18
18
|
* utils.overwriteProperty(chai.Assertion.prototype, 'ok', function (_super) {
|