Skip to content

Commit c8a4e00

Browse files
authoredJul 8, 2021
feat: use chaijs/loupe for inspection (#1401) (#1407)
Fix #1228
1 parent ab41ed8 commit c8a4e00

File tree

9 files changed

+5412
-593
lines changed

9 files changed

+5412
-593
lines changed
 

‎lib/chai/core/assertions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1580,7 +1580,7 @@ module.exports = function (chai, _) {
15801580
, errorMessage
15811581
, shouldThrow = true
15821582
, range = (startType === 'date' && finishType === 'date')
1583-
? start.toUTCString() + '..' + finish.toUTCString()
1583+
? start.toISOString() + '..' + finish.toISOString()
15841584
: start + '..' + finish;
15851585

15861586
if (doLength && objType !== 'map' && objType !== 'set') {

‎lib/chai/utils/inspect.js

+6-352
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
// https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/util.js
33

44
var getName = require('get-func-name');
5-
var getProperties = require('./getProperties');
6-
var getEnumerableProperties = require('./getEnumerableProperties');
5+
var loupe = require('loupe');
76
var config = require('../config');
87

98
module.exports = inspect;
@@ -24,356 +23,11 @@ module.exports = inspect;
2423
* @name inspect
2524
*/
2625
function inspect(obj, showHidden, depth, colors) {
27-
var ctx = {
26+
var options = {
27+
colors: colors,
28+
depth: (typeof depth === 'undefined' ? 2 : depth),
2829
showHidden: showHidden,
29-
seen: [],
30-
stylize: function (str) { return str; }
30+
truncate: config.truncateThreshold ? config.truncateThreshold : Infinity,
3131
};
32-
return formatValue(ctx, obj, (typeof depth === 'undefined' ? 2 : depth));
33-
}
34-
35-
// Returns true if object is a DOM element.
36-
var isDOMElement = function (object) {
37-
if (typeof HTMLElement === 'object') {
38-
return object instanceof HTMLElement;
39-
} else {
40-
return object &&
41-
typeof object === 'object' &&
42-
'nodeType' in object &&
43-
object.nodeType === 1 &&
44-
typeof object.nodeName === 'string';
45-
}
46-
};
47-
48-
function formatValue(ctx, value, recurseTimes) {
49-
// Provide a hook for user-specified inspect functions.
50-
// Check that value is an object with an inspect function on it
51-
if (value && typeof value.inspect === 'function' &&
52-
// Filter out the util module, it's inspect function is special
53-
value.inspect !== exports.inspect &&
54-
// Also filter out any prototype objects using the circular check.
55-
!(value.constructor && value.constructor.prototype === value)) {
56-
var ret = value.inspect(recurseTimes, ctx);
57-
if (typeof ret !== 'string') {
58-
ret = formatValue(ctx, ret, recurseTimes);
59-
}
60-
return ret;
61-
}
62-
63-
// Primitive types cannot have properties
64-
var primitive = formatPrimitive(ctx, value);
65-
if (primitive) {
66-
return primitive;
67-
}
68-
69-
// If this is a DOM element, try to get the outer HTML.
70-
if (isDOMElement(value)) {
71-
if ('outerHTML' in value) {
72-
return value.outerHTML;
73-
// This value does not have an outerHTML attribute,
74-
// it could still be an XML element
75-
} else {
76-
// Attempt to serialize it
77-
try {
78-
if (document.xmlVersion) {
79-
var xmlSerializer = new XMLSerializer();
80-
return xmlSerializer.serializeToString(value);
81-
} else {
82-
// Firefox 11- do not support outerHTML
83-
// It does, however, support innerHTML
84-
// Use the following to render the element
85-
var ns = "http://www.w3.org/1999/xhtml";
86-
var container = document.createElementNS(ns, '_');
87-
88-
container.appendChild(value.cloneNode(false));
89-
var html = container.innerHTML
90-
.replace('><', '>' + value.innerHTML + '<');
91-
container.innerHTML = '';
92-
return html;
93-
}
94-
} catch (err) {
95-
// This could be a non-native DOM implementation,
96-
// continue with the normal flow:
97-
// printing the element as if it is an object.
98-
}
99-
}
100-
}
101-
102-
// Look up the keys of the object.
103-
var visibleKeys = getEnumerableProperties(value);
104-
var keys = ctx.showHidden ? getProperties(value) : visibleKeys;
105-
106-
var name, nameSuffix;
107-
108-
// Some type of object without properties can be shortcut.
109-
// In IE, errors have a single `stack` property, or if they are vanilla `Error`,
110-
// a `stack` plus `description` property; ignore those for consistency.
111-
if (keys.length === 0 || (isError(value) && (
112-
(keys.length === 1 && keys[0] === 'stack') ||
113-
(keys.length === 2 && keys[0] === 'description' && keys[1] === 'stack')
114-
))) {
115-
if (typeof value === 'function') {
116-
name = getName(value);
117-
nameSuffix = name ? ': ' + name : '';
118-
return ctx.stylize('[Function' + nameSuffix + ']', 'special');
119-
}
120-
if (isRegExp(value)) {
121-
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
122-
}
123-
if (isDate(value)) {
124-
return ctx.stylize(Date.prototype.toUTCString.call(value), 'date');
125-
}
126-
if (isError(value)) {
127-
return formatError(value);
128-
}
129-
}
130-
131-
var base = ''
132-
, array = false
133-
, typedArray = false
134-
, braces = ['{', '}'];
135-
136-
if (isTypedArray(value)) {
137-
typedArray = true;
138-
braces = ['[', ']'];
139-
}
140-
141-
// Make Array say that they are Array
142-
if (isArray(value)) {
143-
array = true;
144-
braces = ['[', ']'];
145-
}
146-
147-
// Make functions say that they are functions
148-
if (typeof value === 'function') {
149-
name = getName(value);
150-
nameSuffix = name ? ': ' + name : '';
151-
base = ' [Function' + nameSuffix + ']';
152-
}
153-
154-
// Make RegExps say that they are RegExps
155-
if (isRegExp(value)) {
156-
base = ' ' + RegExp.prototype.toString.call(value);
157-
}
158-
159-
// Make dates with properties first say the date
160-
if (isDate(value)) {
161-
base = ' ' + Date.prototype.toUTCString.call(value);
162-
}
163-
164-
// Make error with message first say the error
165-
if (isError(value)) {
166-
return formatError(value);
167-
}
168-
169-
if (keys.length === 0 && (!array || value.length == 0)) {
170-
return braces[0] + base + braces[1];
171-
}
172-
173-
if (recurseTimes < 0) {
174-
if (isRegExp(value)) {
175-
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
176-
} else {
177-
return ctx.stylize('[Object]', 'special');
178-
}
179-
}
180-
181-
ctx.seen.push(value);
182-
183-
var output;
184-
if (array) {
185-
output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
186-
} else if (typedArray) {
187-
return formatTypedArray(value);
188-
} else {
189-
output = keys.map(function(key) {
190-
return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
191-
});
192-
}
193-
194-
ctx.seen.pop();
195-
196-
return reduceToSingleString(output, base, braces);
197-
}
198-
199-
function formatPrimitive(ctx, value) {
200-
switch (typeof value) {
201-
case 'undefined':
202-
return ctx.stylize('undefined', 'undefined');
203-
204-
case 'string':
205-
var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
206-
.replace(/'/g, "\\'")
207-
.replace(/\\"/g, '"') + '\'';
208-
return ctx.stylize(simple, 'string');
209-
210-
case 'number':
211-
if (value === 0 && (1/value) === -Infinity) {
212-
return ctx.stylize('-0', 'number');
213-
}
214-
return ctx.stylize('' + value, 'number');
215-
216-
case 'boolean':
217-
return ctx.stylize('' + value, 'boolean');
218-
219-
case 'symbol':
220-
return ctx.stylize(value.toString(), 'symbol');
221-
222-
case 'bigint':
223-
return ctx.stylize(value.toString() + 'n', 'bigint');
224-
}
225-
// For some reason typeof null is "object", so special case here.
226-
if (value === null) {
227-
return ctx.stylize('null', 'null');
228-
}
229-
}
230-
231-
function formatError(value) {
232-
return '[' + Error.prototype.toString.call(value) + ']';
233-
}
234-
235-
function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
236-
var output = [];
237-
for (var i = 0, l = value.length; i < l; ++i) {
238-
if (Object.prototype.hasOwnProperty.call(value, String(i))) {
239-
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
240-
String(i), true));
241-
} else {
242-
output.push('');
243-
}
244-
}
245-
246-
keys.forEach(function(key) {
247-
if (!key.match(/^\d+$/)) {
248-
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
249-
key, true));
250-
}
251-
});
252-
return output;
253-
}
254-
255-
function formatTypedArray(value) {
256-
var str = '[ ';
257-
258-
for (var i = 0; i < value.length; ++i) {
259-
if (str.length >= config.truncateThreshold - 7) {
260-
str += '...';
261-
break;
262-
}
263-
str += value[i] + ', ';
264-
}
265-
str += ' ]';
266-
267-
// Removing trailing `, ` if the array was not truncated
268-
if (str.indexOf(', ]') !== -1) {
269-
str = str.replace(', ]', ' ]');
270-
}
271-
272-
return str;
273-
}
274-
275-
function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
276-
var name;
277-
var propDescriptor = Object.getOwnPropertyDescriptor(value, key);
278-
var str;
279-
280-
if (propDescriptor) {
281-
if (propDescriptor.get) {
282-
if (propDescriptor.set) {
283-
str = ctx.stylize('[Getter/Setter]', 'special');
284-
} else {
285-
str = ctx.stylize('[Getter]', 'special');
286-
}
287-
} else {
288-
if (propDescriptor.set) {
289-
str = ctx.stylize('[Setter]', 'special');
290-
}
291-
}
292-
}
293-
if (visibleKeys.indexOf(key) < 0) {
294-
name = '[' + key + ']';
295-
}
296-
if (!str) {
297-
if (ctx.seen.indexOf(value[key]) < 0) {
298-
if (recurseTimes === null) {
299-
str = formatValue(ctx, value[key], null);
300-
} else {
301-
str = formatValue(ctx, value[key], recurseTimes - 1);
302-
}
303-
if (str.indexOf('\n') > -1) {
304-
if (array) {
305-
str = str.split('\n').map(function(line) {
306-
return ' ' + line;
307-
}).join('\n').substr(2);
308-
} else {
309-
str = '\n' + str.split('\n').map(function(line) {
310-
return ' ' + line;
311-
}).join('\n');
312-
}
313-
}
314-
} else {
315-
str = ctx.stylize('[Circular]', 'special');
316-
}
317-
}
318-
if (typeof name === 'undefined') {
319-
if (array && key.match(/^\d+$/)) {
320-
return str;
321-
}
322-
name = JSON.stringify('' + key);
323-
if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
324-
name = name.substr(1, name.length - 2);
325-
name = ctx.stylize(name, 'name');
326-
} else {
327-
name = name.replace(/'/g, "\\'")
328-
.replace(/\\"/g, '"')
329-
.replace(/(^"|"$)/g, "'");
330-
name = ctx.stylize(name, 'string');
331-
}
332-
}
333-
334-
return name + ': ' + str;
335-
}
336-
337-
function reduceToSingleString(output, base, braces) {
338-
var length = output.reduce(function(prev, cur) {
339-
return prev + cur.length + 1;
340-
}, 0);
341-
342-
if (length > 60) {
343-
return braces[0] +
344-
(base === '' ? '' : base + '\n ') +
345-
' ' +
346-
output.join(',\n ') +
347-
' ' +
348-
braces[1];
349-
}
350-
351-
return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
352-
}
353-
354-
function isTypedArray(ar) {
355-
// Unfortunately there's no way to check if an object is a TypedArray
356-
// We have to check if it's one of these types
357-
return (typeof ar === 'object' && /\w+Array]$/.test(objectToString(ar)));
358-
}
359-
360-
function isArray(ar) {
361-
return Array.isArray(ar) ||
362-
(typeof ar === 'object' && objectToString(ar) === '[object Array]');
363-
}
364-
365-
function isRegExp(re) {
366-
return typeof re === 'object' && objectToString(re) === '[object RegExp]';
367-
}
368-
369-
function isDate(d) {
370-
return typeof d === 'object' && objectToString(d) === '[object Date]';
371-
}
372-
373-
function isError(e) {
374-
return typeof e === 'object' && objectToString(e) === '[object Error]';
375-
}
376-
377-
function objectToString(o) {
378-
return Object.prototype.toString.call(o);
32+
return loupe.inspect(obj, options);
37933
}

‎package-lock.json

+5,188-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"check-error": "^1.0.2",
4545
"deep-eql": "^3.0.1",
4646
"get-func-name": "^2.0.0",
47+
"loupe": "^2.3.0",
4748
"pathval": "^1.1.1",
4849
"type-detect": "^4.0.5"
4950
},

‎test/assert.js

+27-27
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe('assert', function () {
7070

7171
err(function () {
7272
assert[isOk](0);
73-
}, "expected 0 to be truthy");
73+
}, "expected +0 to be truthy");
7474

7575
err(function () {
7676
assert[isOk]('');
@@ -107,7 +107,7 @@ describe('assert', function () {
107107

108108
err(function() {
109109
assert.isFalse(0);
110-
}, "expected 0 to be false");
110+
}, "expected +0 to be false");
111111
});
112112

113113
it('isNotFalse', function () {
@@ -273,7 +273,7 @@ describe('assert', function () {
273273

274274
err(function () {
275275
assert.notInstanceOf(new Foo(), Foo, 'blah');
276-
}, "blah: expected {} to not be an instance of Foo");
276+
}, "blah: expected Foo{} to not be an instance of Foo");
277277
});
278278

279279
it('isObject', function () {
@@ -287,7 +287,7 @@ describe('assert', function () {
287287

288288
err(function() {
289289
assert.isObject(Foo);
290-
}, "expected [Function: Foo] to be an object");
290+
}, "expected [Function Foo] to be an object");
291291

292292
err(function() {
293293
assert.isObject('foo');
@@ -353,7 +353,7 @@ describe('assert', function () {
353353

354354
err(function () {
355355
assert.deepEqual({tea: 'chai'}, {tea: 'black'}, 'blah');
356-
}, "blah: expected { tea: \'chai\' } to deeply equal { tea: \'black\' }");
356+
}, "blah: expected { tea: 'chai' } to deeply equal { tea: 'black' }");
357357

358358
var obja = Object.create({ tea: 'chai' })
359359
, objb = Object.create({ tea: 'chai' });
@@ -365,7 +365,7 @@ describe('assert', function () {
365365

366366
err(function () {
367367
assert.deepEqual(obj1, obj2);
368-
}, "expected { tea: \'chai\' } to deeply equal { tea: \'black\' }");
368+
}, "expected {} to deeply equal {}");
369369
});
370370

371371
it('deepEqual (ordering)', function() {
@@ -405,7 +405,7 @@ describe('assert', function () {
405405
err(function() {
406406
secondCircularObject.field2 = secondCircularObject;
407407
assert.deepEqual(circularObject, secondCircularObject);
408-
}, "expected { field: [Circular] } to deeply equal { Object (field, field2) }");
408+
}, "expected { field: [Circular] } to deeply equal { field: [Circular], …(1) }");
409409
});
410410

411411
it('notDeepEqual', function() {
@@ -928,19 +928,19 @@ describe('assert', function () {
928928

929929
err(function () {
930930
assert.deepNestedInclude({a: {b: [{x: 1}]}}, {'a.b[0]': {y: 2}}, 'blah');
931-
}, "blah: expected { a: { b: [ [Object] ] } } to have deep nested property 'a.b[0]' of { y: 2 }, but got { x: 1 }");
931+
}, "blah: expected { a: { b: [ { x: 1 } ] } } to have deep nested property 'a.b[0]' of { y: 2 }, but got { x: 1 }");
932932

933933
err(function () {
934934
assert.deepNestedInclude({a: {b: [{x: 1}]}}, {'a.b[0]': {y: 2}}, 'blah');
935-
}, "blah: expected { a: { b: [ [Object] ] } } to have deep nested property 'a.b[0]' of { y: 2 }, but got { x: 1 }");
935+
}, "blah: expected { a: { b: [ { x: 1 } ] } } to have deep nested property 'a.b[0]' of { y: 2 }, but got { x: 1 }");
936936

937937
err(function () {
938938
assert.deepNestedInclude({a: {b: [{x: 1}]}}, {'a.c': {x: 1}});
939-
}, "expected { a: { b: [ [Object] ] } } to have deep nested property 'a.c'");
939+
}, "expected { a: { b: [ { x: 1 } ] } } to have deep nested property 'a.c'");
940940

941941
err(function () {
942942
assert.notDeepNestedInclude({a: {b: [{x: 1}]}}, {'a.b[0]': {x: 1}}, 'blah');
943-
}, "blah: expected { a: { b: [ [Object] ] } } to not have deep nested property 'a.b[0]' of { x: 1 }");
943+
}, "blah: expected { a: { b: [ { x: 1 } ] } } to not have deep nested property 'a.b[0]' of { x: 1 }");
944944
});
945945

946946
it('ownInclude and notOwnInclude', function() {
@@ -1424,7 +1424,7 @@ describe('assert', function () {
14241424

14251425
err(function(){
14261426
assert.lengthOf(map, 3, 'blah');
1427-
}, "blah: expected {} to have a size of 3 but got 2");
1427+
}, "blah: expected Map{ 'a' => 1, 'b' => 2 } to have a size of 3 but got 2");
14281428
}
14291429

14301430
if (typeof Set === 'function') {
@@ -1438,7 +1438,7 @@ describe('assert', function () {
14381438

14391439
err(function(){
14401440
assert.lengthOf(set, 3, 'blah');
1441-
}, "blah: expected {} to have a size of 3 but got 2");
1441+
}, "blah: expected Set{ 1, 2 } to have a size of 3 but got 2");
14421442
}
14431443
});
14441444

@@ -2026,7 +2026,7 @@ describe('assert', function () {
20262026

20272027
err(function() {
20282028
assert.includeMembers([5, 6], [5, 6, 0]);
2029-
}, 'expected [ 5, 6 ] to be a superset of [ 5, 6, 0 ]');
2029+
}, 'expected [ 5, 6 ] to be a superset of [ 5, 6, +0 ]');
20302030
});
20312031

20322032
it('notIncludeMembers', function() {
@@ -2051,7 +2051,7 @@ describe('assert', function () {
20512051

20522052
err(function() {
20532053
assert.includeDeepMembers([{e:5}, {f:6}], [{e:5}, {f:6}, {z:0}]);
2054-
}, 'expected [ { e: 5 }, { f: 6 } ] to be a superset of [ { e: 5 }, { f: 6 }, { z: 0 } ]');
2054+
}, 'expected [ { e: 5 }, { f: 6 } ] to be a superset of [ { e: 5 }, { f: 6 }, { z: +0 } ]');
20552055
});
20562056

20572057
it('notIncludeDeepMembers', function() {
@@ -2155,11 +2155,11 @@ describe('assert', function () {
21552155

21562156
err(function() {
21572157
assert.isAbove(oneSecondAgo, now, 'blah');
2158-
}, 'blah: expected ' + oneSecondAgo.toUTCString() + ' to be above ' + now.toUTCString());
2158+
}, 'blah: expected ' + oneSecondAgo.toISOString() + ' to be above ' + now.toISOString());
21592159

21602160
err(function() {
21612161
assert.isAbove(now, now, 'blah');
2162-
}, 'blah: expected ' + now.toUTCString() + ' to be above ' + now.toUTCString());
2162+
}, 'blah: expected ' + now.toISOString() + ' to be above ' + now.toISOString());
21632163

21642164
err(function() {
21652165
assert.isAbove(null, now);
@@ -2205,7 +2205,7 @@ describe('assert', function () {
22052205

22062206
err(function() {
22072207
assert.isAtLeast(now, oneSecondAfter, 'blah');
2208-
}, 'blah: expected ' + now.toUTCString() + ' to be at least ' + oneSecondAfter.toUTCString());
2208+
}, 'blah: expected ' + now.toISOString() + ' to be at least ' + oneSecondAfter.toISOString());
22092209

22102210
err(function() {
22112211
assert.isAtLeast(null, now, 'blah');
@@ -2251,11 +2251,11 @@ describe('assert', function () {
22512251

22522252
err(function() {
22532253
assert.isBelow(now, oneSecondAgo, 'blah');
2254-
}, 'blah: expected ' + now.toUTCString() + ' to be below ' + oneSecondAgo.toUTCString());
2254+
}, 'blah: expected ' + now.toISOString() + ' to be below ' + oneSecondAgo.toISOString());
22552255

22562256
err(function() {
22572257
assert.isBelow(now, now);
2258-
}, 'expected ' + now.toUTCString() + ' to be below ' + now.toUTCString());
2258+
}, 'expected ' + now.toISOString() + ' to be below ' + now.toISOString());
22592259

22602260
err(function() {
22612261
assert.isBelow(null, now, 'blah');
@@ -2301,7 +2301,7 @@ describe('assert', function () {
23012301

23022302
err(function() {
23032303
assert.isAtMost(oneSecondAfter, now, 'blah');
2304-
}, 'blah: expected ' + oneSecondAfter.toUTCString() + ' to be at most ' + now.toUTCString());
2304+
}, 'blah: expected ' + oneSecondAfter.toISOString() + ' to be at most ' + now.toISOString());
23052305

23062306
err(function() {
23072307
assert.isAtMost(null, now, 'blah');
@@ -2781,7 +2781,7 @@ describe('assert', function () {
27812781

27822782
err(function(){
27832783
assert[isEmpty]({arguments: 0});
2784-
}, "expected { arguments: 0 } to be empty");
2784+
}, "expected { arguments: +0 } to be empty");
27852785

27862786
err(function(){
27872787
assert[isEmpty]({foo: 'bar'});
@@ -2801,7 +2801,7 @@ describe('assert', function () {
28012801

28022802
err(function(){
28032803
assert[isEmpty](0);
2804-
}, ".empty was passed non-string primitive 0");
2804+
}, ".empty was passed non-string primitive +0");
28052805

28062806
err(function(){
28072807
assert[isEmpty](1);
@@ -2867,7 +2867,7 @@ describe('assert', function () {
28672867

28682868
err(function(){
28692869
assert[isNotEmpty](new Map);
2870-
}, "expected {} not to be empty");
2870+
}, "expected Map{} not to be empty");
28712871
}
28722872

28732873
if (typeof Set === 'function') {
@@ -2878,7 +2878,7 @@ describe('assert', function () {
28782878

28792879
err(function(){
28802880
assert[isNotEmpty](new Set);
2881-
}, "expected {} not to be empty");
2881+
}, "expected Set{} not to be empty");
28822882
}
28832883

28842884
err(function(){
@@ -2891,7 +2891,7 @@ describe('assert', function () {
28912891

28922892
err(function(){
28932893
assert[isNotEmpty](new FakeArgs);
2894-
}, "expected { length: 0 } not to be empty");
2894+
}, "expected FakeArgs{} not to be empty");
28952895

28962896
err(function(){
28972897
assert[isNotEmpty]({});
@@ -2911,7 +2911,7 @@ describe('assert', function () {
29112911

29122912
err(function(){
29132913
assert[isNotEmpty](0);
2914-
}, ".empty was passed non-string primitive 0");
2914+
}, ".empty was passed non-string primitive +0");
29152915

29162916
err(function(){
29172917
assert[isNotEmpty](1);

‎test/expect.js

+90-90
Large diffs are not rendered by default.

‎test/globalErr.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ describe('globalErr', function () {
103103
err(function () {
104104
expect(f1).to.equal(f2);
105105
}, {
106-
message: "expected [Function: f1] to equal [Function: f2]"
106+
message: "expected [Function f1] to equal [Function f2]"
107107
, expected: f2
108108
, actual: f1
109109
, operator: 'deepStrictEqual'
@@ -112,7 +112,7 @@ describe('globalErr', function () {
112112
err(function () {
113113
expect(f1).to.not.equal(f1);
114114
}, {
115-
message: "expected [Function: f1] to not equal [Function: f1]"
115+
message: "expected [Function f1] to not equal [Function f1]"
116116
, expected: f1
117117
, actual: f1
118118
, operator: 'notDeepStrictEqual'
@@ -136,7 +136,7 @@ describe('globalErr', function () {
136136
err(function () {
137137
expect(val1).to.equal(val2);
138138
}, {
139-
message: 'expected [ Array(4) ] to equal [ Array(4) ]'
139+
message: "expected [ 'string1', 'string2', …(2) ] to equal [ 'string5', 'string6', …(2) ]"
140140
, expected: val2
141141
, actual: val1
142142
, operator: 'deepStrictEqual'
@@ -145,7 +145,7 @@ describe('globalErr', function () {
145145
err(function () {
146146
expect(val1).to.not.equal(val1);
147147
}, {
148-
message: 'expected [ Array(4) ] to not equal [ Array(4) ]'
148+
message: "expected [ 'string1', 'string2', …(2) ] to not equal [ 'string1', 'string2', …(2) ]"
149149
, expected: val1
150150
, actual: val1
151151
, operator: 'notDeepStrictEqual'
@@ -161,7 +161,7 @@ describe('globalErr', function () {
161161
it('should throw if object val\'s props are not included in error object', function () {
162162
err(function () {
163163
err(function () { throw new Err('cat') }, {text: 'cat'});
164-
}, /expected { Object \(message, showDiff(, \.\.\.)*\) } to have property \'text\'/);
164+
}, /expected AssertionError{ message: 'cat', \(2\) } to have property \'text\'/);
165165

166166
err(function () {
167167
err(function () { throw new Err('cat') }, {message: 'dog'});

‎test/should.js

+82-82
Large diffs are not rendered by default.

‎test/utilities.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ describe('utilities', function () {
769769
it('inspect every kind of available TypedArray', function () {
770770
chai.use(function (_chai, _) {
771771
var arr = [1, 2, 3]
772-
, exp = '[ 1, 2, 3 ]'
772+
, exp = 'Array[ 1, 2, 3 ]'
773773
, isNode = true;
774774

775775
if (typeof window !== 'undefined') {
@@ -780,24 +780,24 @@ describe('utilities', function () {
780780
if ((!isNode && 'Int8Array' in window) ||
781781
isNode && typeof 'Int8Array' !== undefined) {
782782
// Typed array inspections should work as array inspections do
783-
expect(_.inspect(new Int8Array(arr))).to.equal(exp);
784-
expect(_.inspect(new Uint8Array(arr))).to.equal(exp);
785-
expect(_.inspect(new Int16Array(arr))).to.equal(exp);
786-
expect(_.inspect(new Uint16Array(arr))).to.equal(exp);
787-
expect(_.inspect(new Int32Array(arr))).to.equal(exp);
788-
expect(_.inspect(new Uint32Array(arr))).to.equal(exp);
789-
expect(_.inspect(new Float32Array(arr))).to.equal(exp);
783+
expect(_.inspect(new Int8Array(arr))).to.include(exp);
784+
expect(_.inspect(new Uint8Array(arr))).to.include(exp);
785+
expect(_.inspect(new Int16Array(arr))).to.include(exp);
786+
expect(_.inspect(new Uint16Array(arr))).to.include(exp);
787+
expect(_.inspect(new Int32Array(arr))).to.include(exp);
788+
expect(_.inspect(new Uint32Array(arr))).to.include(exp);
789+
expect(_.inspect(new Float32Array(arr))).to.include(exp);
790790
}
791791

792792
// These ones may not be available alongside the others above
793793
if ((!isNode && 'Uint8ClampedArray' in window) ||
794794
isNode && typeof 'Uint8ClampedArray' !== undefined) {
795-
expect(_.inspect(new Uint8ClampedArray(arr))).to.equal(exp);
795+
expect(_.inspect(new Uint8ClampedArray(arr))).to.include(exp);
796796
}
797797

798798
if ((!isNode && 'Float64Array' in window) ||
799799
isNode && typeof 'Float64Array' !== undefined) {
800-
expect(_.inspect(new Float64Array(arr))).to.equal(exp);
800+
expect(_.inspect(new Float64Array(arr))).to.include(exp);
801801
}
802802
});
803803
});
@@ -817,7 +817,7 @@ describe('utilities', function () {
817817
chai.use(function (_chai, _) {
818818

819819
var arr = []
820-
, exp = '[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ... ]'
820+
, exp = 'Int8Array[ 1, 2, 3, 4, 5, 6, 7, …(993) ]'
821821
, isNode = true;
822822

823823
// Filling arr with lots of elements
@@ -831,7 +831,7 @@ describe('utilities', function () {
831831

832832
if ((!isNode && 'Int8Array' in window) ||
833833
isNode && typeof 'Int8Array' !== undefined) {
834-
expect(_.inspect(new Int8Array(arr))).to.equal(exp);
834+
expect(_.inspect(new Int8Array(arr))).to.include(exp);
835835
}
836836
});
837837
});

0 commit comments

Comments
 (0)
Please sign in to comment.