assert.doesNotMatch(string, regexp[, message])
期望 string 输入不匹配正则表达式。
【Expects the string input not to match the regular expression.】
import assert from 'node:assert/strict';
assert.doesNotMatch('I will fail', /fail/);
// AssertionError [ERR_ASSERTION]: The input was expected to not match the ...
assert.doesNotMatch(123, /pass/);
// AssertionError [ERR_ASSERTION]: The "string" argument must be of type string.
assert.doesNotMatch('I will pass', /different/);
// OKconst assert = require('node:assert/strict');
assert.doesNotMatch('I will fail', /fail/);
// AssertionError [ERR_ASSERTION]: The input was expected to not match the ...
assert.doesNotMatch(123, /pass/);
// AssertionError [ERR_ASSERTION]: The "string" argument must be of type string.
assert.doesNotMatch('I will pass', /different/);
// OK如果值匹配,或者 string 参数的类型不是 string,将抛出一个 AssertionError,其 message 属性被设置为 message 参数的值。如果 message 参数未定义,则会分配一个默认的错误消息。如果 message 参数是 Error 的实例,则会抛出该实例而不是 AssertionError。
【If the values do match, or if the string argument is of another type than
string, an AssertionError is thrown with a message property set equal
to the value of the message parameter. If the message parameter is
undefined, a default error message is assigned. If the message parameter is an
instance of an Error then it will be thrown instead of the
AssertionError.】