Browse Source

add t.notRegex (#879)

* add t.notRegex

Fixes #877

* add notRegex to power-assert patterns
browser-support
James Talmage 9 years ago
parent
commit
c7402023d6
  1. 4
      lib/assert.js
  2. 1
      lib/enhance-assert.js
  3. 4
      readme.md
  4. 12
      test/assert.js

4
lib/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));
};

1
lib/enhance-assert.js

@ -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])',

4
readme.md

@ -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.

12
test/assert.js

@ -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());

Loading…
Cancel
Save