Skip to content

Commit

Permalink
[Fix] match/doesNotMatch: when passing, ensure the proper default…
Browse files Browse the repository at this point in the history
… assert message shows up

Fixes #494.
  • Loading branch information
ljharb committed Jan 9, 2020
1 parent 1fba54a commit 8af61fd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,12 @@ Test.prototype.match = function match(string, regexp, msg, extra) {
}

var matches = $test(regexp, string);
var message = defined(
msg,
'The input ' + (matches ? 'matched' : 'did not match') + ' the regular expression ' + inspect(regexp) + '. Input: ' + inspect(string)
);
this._assert(matches, {
message: defined(msg, 'The input did not match the regular expression ' + inspect(regexp) + '. Input: ' + inspect(string)),
message: message,
operator: 'match',
actual: string,
expected: regexp,
Expand All @@ -573,8 +577,12 @@ Test.prototype.doesNotMatch = function doesNotMatch(string, regexp, msg, extra)
throw new TypeError('The "string" argument must be of type string. Received type ' + typeof string + ' (' + inspect(string) + ')');
}
var matches = $test(regexp, string);
var message = defined(
msg,
'The input ' + (matches ? 'was expected to not match' : 'did not match') + ' the regular expression ' + inspect(regexp) + '. Input: ' + inspect(string)
);
this._assert(!matches, {
message: defined(msg, 'The input was expected to not match the regular expression ' + inspect(regexp) + '. Input: ' + inspect(string)),
message: message,
operator: 'doesNotMatch',
actual: string,
expected: regexp,
Expand Down
2 changes: 1 addition & 1 deletion test/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ tap.test('match', function (tt) {
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 5 The input did not match the regular expression /pass$/. Input: \'I will pass\'',
'ok 5 The input matched the regular expression /pass$/. Input: \'I will pass\'',
'ok 6 "I will pass" matches /pass$/',
'',
'1..6',
Expand Down

0 comments on commit 8af61fd

Please sign in to comment.