Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand .with message to include actual results #52

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions chai-spies.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,10 @@

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

this.assert(
passed > 0
, 'expected ' + this._obj + ' to have been called with #{exp}'
, 'expected ' + this._his + ' to have not been called with #{exp} but got ' + passed + ' times'
, 'expected ' + this._obj + ' to have been called with ' + _.inspect(args, false, 2) + ' at least once'
+ (calls.length
? ', but it was actually called ' + calls.length + ' times with:' + calls.map(function (call, i) {
return '\ncall #' + (i + 1) + ': ' + _.inspect(call, false, 2);
}).join('')
: ', but it was actually not called'
)
, 'expected ' + this._his + ' to have not been called with ' + _.inspect(args, false, 2)
+ ', but it actually was called ' + passed + ' times with those arguments, out of ' + calls.length + ' total calls'
, args
);
}
Expand Down
17 changes: 13 additions & 4 deletions lib/spy.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,10 @@ module.exports = function (chai, _) {

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

this.assert(
passed > 0
, 'expected ' + this._obj + ' to have been called with #{exp}'
, 'expected ' + this._his + ' to have not been called with #{exp} but got ' + passed + ' times'
, 'expected ' + this._obj + ' to have been called with ' + _.inspect(args, false, 2) + ' at least once'
+ (calls.length
? ', but it was actually called ' + calls.length + ' times with:' + calls.map(function (call, i) {
return '\ncall #' + (i + 1) + ': ' + _.inspect(call, false, 2);
}).join('')
: ', but it was actually not called'
)
, 'expected ' + this._his + ' to have not been called with ' + _.inspect(args, false, 2)
+ ', but it actually was called ' + passed + ' times with those arguments, out of ' + calls.length + ' total calls'
, args
);
}
Expand Down