Skip to content

Commit a10b9e8

Browse files
committed
add .regex() assertion method
Reimplementation of `.regexTest()`, with arguments flipped.
1 parent 761c2e3 commit a10b9e8

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

lib/assert.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ x.doesNotThrow = function (fn, msg) {
122122
}
123123
};
124124

125-
x.regexTest = function (regex, contents, msg) {
126-
test(regex.test(contents), create(regex, contents, '===', msg, x.regexTest));
125+
x.regex = function (contents, regex, msg) {
126+
test(regex.test(contents), create(regex, contents, '===', msg, x.regex));
127127
};
128128

129129
x.ifError = x.error = function (err, msg) {

lib/enhance-assert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports.PATTERNS = [
1010
't.not(value, expected, [message])',
1111
't.same(value, expected, [message])',
1212
't.notSame(value, expected, [message])',
13-
't.regexTest(regex, contents, [message])'
13+
't.regex(contents, regex, [message])'
1414
];
1515

1616
module.exports.NON_ENHANCED_PATTERNS = [

readme.md

+4
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,10 @@ Assert that `function` throws an error or `promise` rejects.
594594

595595
Assert that `function` doesn't throw an `error` or `promise` resolves.
596596

597+
### .regex(contents, regex, [message])
598+
599+
Assert that `contents` matches `regex`.
600+
597601
### .ifError(error, [message])
598602

599603
Assert that `error` is falsy.

test/assert.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,13 @@ test('.doesNotThrow()', function (t) {
196196
t.end();
197197
});
198198

199-
test('.regexTest()', function (t) {
199+
test('.regex()', function (t) {
200200
t.doesNotThrow(function () {
201-
assert.regexTest(/^abc$/, 'abc');
201+
assert.regex('abc', /^abc$/);
202202
});
203203

204204
t.throws(function () {
205-
assert.regexTest(/^abc$/, 'foo');
205+
assert.regex('foo', /^abc$/);
206206
});
207207

208208
t.end();

0 commit comments

Comments
 (0)