Skip to content

Commit 8af61fd

Browse files
committed
[Fix] match/doesNotMatch: when passing, ensure the proper default assert message shows up
Fixes #494.
1 parent 1fba54a commit 8af61fd

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Diff for: lib/test.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,12 @@ Test.prototype.match = function match(string, regexp, msg, extra) {
556556
}
557557

558558
var matches = $test(regexp, string);
559+
var message = defined(
560+
msg,
561+
'The input ' + (matches ? 'matched' : 'did not match') + ' the regular expression ' + inspect(regexp) + '. Input: ' + inspect(string)
562+
);
559563
this._assert(matches, {
560-
message: defined(msg, 'The input did not match the regular expression ' + inspect(regexp) + '. Input: ' + inspect(string)),
564+
message: message,
561565
operator: 'match',
562566
actual: string,
563567
expected: regexp,
@@ -573,8 +577,12 @@ Test.prototype.doesNotMatch = function doesNotMatch(string, regexp, msg, extra)
573577
throw new TypeError('The "string" argument must be of type string. Received type ' + typeof string + ' (' + inspect(string) + ')');
574578
}
575579
var matches = $test(regexp, string);
580+
var message = defined(
581+
msg,
582+
'The input ' + (matches ? 'was expected to not match' : 'did not match') + ' the regular expression ' + inspect(regexp) + '. Input: ' + inspect(string)
583+
);
576584
this._assert(!matches, {
577-
message: defined(msg, 'The input was expected to not match the regular expression ' + inspect(regexp) + '. Input: ' + inspect(string)),
585+
message: message,
578586
operator: 'doesNotMatch',
579587
actual: string,
580588
expected: regexp,

Diff for: test/match.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ tap.test('match', function (tt) {
4040
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
4141
' [... stack stripped ...]',
4242
' ...',
43-
'ok 5 The input did not match the regular expression /pass$/. Input: \'I will pass\'',
43+
'ok 5 The input matched the regular expression /pass$/. Input: \'I will pass\'',
4444
'ok 6 "I will pass" matches /pass$/',
4545
'',
4646
'1..6',

0 commit comments

Comments
 (0)