diff --git a/lib/assert.js b/lib/assert.js index 64b523256..691414288 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -122,8 +122,8 @@ x.doesNotThrow = function (fn, msg) { } }; -x.regexTest = function (regex, contents, msg) { - test(regex.test(contents), create(regex, contents, '===', msg, x.regexTest)); +x.regex = function (contents, regex, msg) { + test(regex.test(contents), create(regex, contents, '===', msg, x.regex)); }; x.ifError = x.error = function (err, msg) { diff --git a/lib/enhance-assert.js b/lib/enhance-assert.js index 983615dd1..ce692957f 100644 --- a/lib/enhance-assert.js +++ b/lib/enhance-assert.js @@ -10,7 +10,7 @@ module.exports.PATTERNS = [ 't.not(value, expected, [message])', 't.same(value, expected, [message])', 't.notSame(value, expected, [message])', - 't.regexTest(regex, contents, [message])' + 't.regex(contents, regex, [message])' ]; module.exports.NON_ENHANCED_PATTERNS = [ diff --git a/readme.md b/readme.md index bcb3519e7..8d3e3526d 100644 --- a/readme.md +++ b/readme.md @@ -594,6 +594,10 @@ Assert that `function` throws an error or `promise` rejects. Assert that `function` doesn't throw an `error` or `promise` resolves. +### .regex(contents, regex, [message]) + +Assert that `contents` matches `regex`. + ### .ifError(error, [message]) Assert that `error` is falsy. diff --git a/test/assert.js b/test/assert.js index 83561005b..65178e607 100644 --- a/test/assert.js +++ b/test/assert.js @@ -196,13 +196,13 @@ test('.doesNotThrow()', function (t) { t.end(); }); -test('.regexTest()', function (t) { +test('.regex()', function (t) { t.doesNotThrow(function () { - assert.regexTest(/^abc$/, 'abc'); + assert.regex('abc', /^abc$/); }); t.throws(function () { - assert.regexTest(/^abc$/, 'foo'); + assert.regex('foo', /^abc$/); }); t.end();