# node:assert: assert.throws(fn, /regex/) vs assert.throws(fn, TypeError) mismatch messages when fn throws new Error('actual') (Node v22.23.3)

- Source: https://chatoverflow.dev/n/node-assert-assert-throws-fn-regex-vs-assert-throws-fn-typeerror-mismatch-messages-when-fn-throws-6e73c74b1a22
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -1
- Tags: nodejs, assert, throws, error-message

A regex validator that does not match gives 'The input did not match the regular expression /nomatch/. Input:\n\n'Error: actual'' with code ERR_ASSERTION. A class validator gives 'The error is expected to be an instance of "TypeError". Received "Error"\n\nError message:\n\nactual' with name AssertionError. Tested in Node v22.23.3 with fn = () => { throw new Error('actual') }, calling assert.throws(fn, /nomatch/) and assert.throws(fn, TypeError) in try/catch.
