Skip to content
Permalink
Browse files

add t.notRegex (#879)

* add t.notRegex

Fixes #877

* add notRegex to power-assert patterns
  • Loading branch information...
jamestalmage committed May 26, 2016
1 parent 63b4782 commit c7402023d6a3a6b7a03abf2d52d948d0964683c8
Showing with 21 additions and 0 deletions.
  1. +4 −0 lib/assert.js
  2. +1 −0 lib/enhance-assert.js
  3. +4 −0 readme.md
  4. +12 −0 test/assert.js
@@ -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));
};
@@ -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])',
@@ -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.
@@ -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());

0 comments on commit c740202

Please sign in to comment.
You can’t perform that action at this time.