{"record":{"id":"1c71359a6b2dae71","repo":"avajs/ava","slug":"t-notregex-must-be-called-with-a-regular-expre","errorCode":null,"errorMessage":"`t.notRegex()` must be called with a regular expression","messagePattern":"`t\\.notRegex\\(\\)` must be called with a regular expression","errorType":"validation","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"lib/assert.js","lineNumber":780,"sourceCode":"\t\t\t\t\t],\n\t\t\t\t}));\n\t\t\t}\n\n\t\t\treturn pass();\n\t\t});\n\n\t\tthis.notRegex = withSkip((string, regex, message) => {\n\t\t\tassertMessage(message, 't.notRegex()');\n\n\t\t\tif (typeof string !== 'string') {\n\t\t\t\tthrow fail(new AssertionError('`t.notRegex()` must be called with a string', {\n\t\t\t\t\tassertion: 't.notRegex()',\n\t\t\t\t\tformattedDetails: [formatWithLabel('Called with:', string)],\n\t\t\t\t}));\n\t\t\t}\n\n\t\t\tif (!(regex instanceof RegExp)) {\n\t\t\t\tthrow fail(new AssertionError('`t.notRegex()` must be called with a regular expression', {\n\t\t\t\t\tassertion: 't.notRegex()',\n\t\t\t\t\tformattedDetails: [formatWithLabel('Called with:', regex)],\n\t\t\t\t}));\n\t\t\t}\n\n\t\t\tif (regex.test(string)) {\n\t\t\t\tthrow fail(new AssertionError(message, {\n\t\t\t\t\tassertion: 't.notRegex()',\n\t\t\t\t\tformattedDetails: [\n\t\t\t\t\t\tformatWithLabel('Value must not match expression:', string),\n\t\t\t\t\t\tformatWithLabel('Regular expression:', regex),\n\t\t\t\t\t],\n\t\t\t\t}));\n\t\t\t}\n\n\t\t\treturn pass();\n\t\t});\n","sourceCodeStart":762,"sourceCodeEnd":798,"githubUrl":"https://github.com/avajs/ava/blob/bbfd946322fdeca2b547a691d947fb4e18c0c67f/lib/assert.js#L762-L798","documentation":"t.notRegex() requires its second argument to be a RegExp instance. If the second argument is not an RegExp (e.g. a string pattern, undefined, or null), AVA throws this AssertionError instead of performing the assertion. This is a usage error because the assertion is meaningless without a regular expression to test against.","triggerScenarios":"Calling t.notRegex(string, x) where x is not an RegExp: passing a pattern string like t.notRegex('foo', 'bar'), passing undefined because the regex variable was never assigned, or passing a regex-like object created with Object.create(RegExp.prototype).","commonSituations":"Developers coming from other frameworks pass a string pattern instead of a regex literal; a regex built with new RegExp(...) from dynamic input ends up undefined due to an earlier error or bad config; TypeScript types were bypassed with `any`.","solutions":["Pass a real regex literal or RegExp instance: t.notRegex(str, /pattern/) or t.notRegex(str, new RegExp(pattern)).","If you have a pattern string, wrap it: new RegExp(patternString) — but escape user input properly.","Log/inspect the variable to see why it is undefined or not a RegExp before the assertion call.","Check argument order — the RegExp must be the second argument; swapping the string and regex triggers this error."],"exampleFix":"// before\nt.notRegex(output, 'ERROR:');\n// after\nt.notRegex(output, /ERROR:/);","handlingStrategy":"type-guard","validationCode":"if (!(regex instanceof RegExp)) { throw new TypeError('t.notRegex() requires a RegExp; got ' + typeof regex); }\nt.notRegex(value, regex);","typeGuard":"function isRegExp(v) { return v instanceof RegExp; }","tryCatchPattern":"try {\n  t.notRegex(value, pattern);\n} catch (err) {\n  if (err.name === 'AssertionError' && /must be called with a regular expression/.test(err.message)) {\n    throw new Error('Test bug: second argument must be a RegExp, got: ' + String(pattern));\n  }\n  throw err;\n}","preventionTips":["Use regex literals (/pattern/) instead of strings for patterns.","Wrap dynamic pattern strings with new RegExp(...) and verify the result is defined.","In TypeScript, type the parameter as RegExp to catch string patterns at compile time.","Check that variables holding regexes are initialized before use."],"tags":["assertion","regexp","ava","argument-validation"],"backgroundTag":"assertion-invalid-argument-type","analyzedSha":"bbfd946322fdeca2b547a691d947fb4e18c0c67f","analyzedAt":"2026-09-02T01:24:43.834Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}