Skip to content

Commit

Permalink
add t.notRegex (#879)
Browse files Browse the repository at this point in the history
* add t.notRegex

Fixes #877

* add notRegex to power-assert patterns
  • Loading branch information
jamestalmage committed May 26, 2016
1 parent 63b4782 commit c740202
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/assert.js
Expand Up @@ -142,6 +142,10 @@ x.regex = function (contents, regex, msg) {
test(regex.test(contents), create(regex, contents, '===', msg, x.regex));
};

x.notRegex = function (contents, regex, msg) {
test(!regex.test(contents), create(regex, contents, '!==', msg, x.notRegex));
};

x.ifError = x.error = function (err, msg) {
test(!err, create(err, 'Error', '!==', msg, x.ifError));
};
Expand Down
1 change: 1 addition & 0 deletions lib/enhance-assert.js
Expand Up @@ -13,6 +13,7 @@ module.exports.PATTERNS = [
't.deepEqual(value, expected, [message])',
't.notDeepEqual(value, expected, [message])',
't.regex(contents, regex, [message])',
't.notRegex(contents, regex, [message])',
// deprecated apis
't.ok(value, [message])',
't.notOk(value, [message])',
Expand Down
4 changes: 4 additions & 0 deletions readme.md
Expand Up @@ -878,6 +878,10 @@ Assert that `function` doesn't throw an `error` or `promise` resolves.

Assert that `contents` matches `regex`.

### `.notRegex(contents, regex, [message])`

Assert that `contents` does not match `regex`.

### `.ifError(error, [message])`

Assert that `error` is falsy.
Expand Down
12 changes: 12 additions & 0 deletions test/assert.js
Expand Up @@ -345,6 +345,18 @@ test('.regex()', function (t) {
t.end();
});

test('.notRegex()', function (t) {
t.doesNotThrow(function () {
assert.notRegex('abc', /def/);
});

t.throws(function () {
assert.notRegex('abc', /abc/);
});

t.end();
});

test('.ifError()', function (t) {
t.throws(function () {
assert.ifError(new Error());
Expand Down

0 comments on commit c740202

Please sign in to comment.