Skip to content

Commit 5b9a0b3

Browse files
committed
Expand .with message to include actual results
1 parent eb493cf commit 5b9a0b3

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

chai-spies.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,10 @@
299299

300300
this.assert(
301301
passed === calls.length
302-
, 'expected ' + this._obj + ' to have been always called with #{exp} but got ' + passed + ' out of ' + calls.length
303-
, 'expected ' + this._his + ' to have not always been called with #{exp}'
302+
, 'expected ' + this._obj + ' to have been always called with ' + _.inspect(args, false, 2)
303+
+ ', but it was actually called ' + passed + ' times with those arguments out of ' + calls.length + ' total calls'
304+
, 'expected ' + this._his + ' to have not always been called with ' + _.inspect(args, false, 2)
305+
+ ', but it was actually called ' + passed + ' times with those arguments out of ' + calls.length + ' total calls'
304306
, args
305307
);
306308
} else {
@@ -317,8 +319,15 @@
317319

318320
this.assert(
319321
passed > 0
320-
, 'expected ' + this._obj + ' to have been called with #{exp}'
321-
, 'expected ' + this._his + ' to have not been called with #{exp} but got ' + passed + ' times'
322+
, 'expected ' + this._obj + ' to have been called with ' + _.inspect(args, false, 2) + ' at least once'
323+
+ (calls.length
324+
? ', but it was actually called ' + calls.length + ' times with:' + calls.map(function (call, i) {
325+
return '\ncall #' + (i + 1) + ': ' + _.inspect(call, false, 2);
326+
}).join('')
327+
: ', but it was actually not called'
328+
)
329+
, 'expected ' + this._his + ' to have not been called with ' + _.inspect(args, false, 2)
330+
+ ', but it actually was called ' + passed + ' times with those arguments, out of ' + calls.length + ' total calls'
322331
, args
323332
);
324333
}

lib/spy.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,10 @@ module.exports = function (chai, _) {
283283

284284
this.assert(
285285
passed === calls.length
286-
, 'expected ' + this._obj + ' to have been always called with #{exp} but got ' + passed + ' out of ' + calls.length
287-
, 'expected ' + this._his + ' to have not always been called with #{exp}'
286+
, 'expected ' + this._obj + ' to have been always called with ' + _.inspect(args, false, 2)
287+
+ ', but it was actually called ' + passed + ' times with those arguments out of ' + calls.length + ' total calls'
288+
, 'expected ' + this._his + ' to have not always been called with ' + _.inspect(args, false, 2)
289+
+ ', but it was actually called ' + passed + ' times with those arguments out of ' + calls.length + ' total calls'
288290
, args
289291
);
290292
} else {
@@ -301,8 +303,15 @@ module.exports = function (chai, _) {
301303

302304
this.assert(
303305
passed > 0
304-
, 'expected ' + this._obj + ' to have been called with #{exp}'
305-
, 'expected ' + this._his + ' to have not been called with #{exp} but got ' + passed + ' times'
306+
, 'expected ' + this._obj + ' to have been called with ' + _.inspect(args, false, 2) + ' at least once'
307+
+ (calls.length
308+
? ', but it was actually called ' + calls.length + ' times with:' + calls.map(function (call, i) {
309+
return '\ncall #' + (i + 1) + ': ' + _.inspect(call, false, 2);
310+
}).join('')
311+
: ', but it was actually not called'
312+
)
313+
, 'expected ' + this._his + ' to have not been called with ' + _.inspect(args, false, 2)
314+
+ ', but it actually was called ' + passed + ' times with those arguments, out of ' + calls.length + ' total calls'
306315
, args
307316
);
308317
}

0 commit comments

Comments
 (0)