According to node.js assert library documentation:
The module is intended for internal use by Node.js, but can be used in
application code via require('assert'). However, assert is not a
testing framework, and is not intended to be used as a general purpose
https://github.com/nodejs/node/issues/4532 and other issues allude to the reason the documentation recommends against using
assert for unit testing: There are edge case bugs (or at least certainly surprises) and missing features.
A little more context: Knowing what we now know, if we were designing/building Node.js core all over again, the
assert module would either not exist in Node.js or else consist of far fewer functions--quite possibly just
assert() (which is currently an alias for
The reasons for this, at least from my perspective, are:
assertcould easily be done in userland
There's additional context that others may choose to add here or not (such as why, all things being equal, we would favor keeping core small and doing things in userland). But that's the so-called 30,000 foot view.
assert has been in Node.js for a long time and a lot of the ecosystem depends on it, we are unlikely (at least as best as I can tell at the current time) to ever remove
assert.throws() and friends. It would break too much stuff. But we can discourage people from using
assert and encourage them to use userland modules that are maintained by people who care deeply about them and who aggressively fix edge-case bugs and who add cool new features when it makes sense. So that's what that's all about.
True, if you're doing straightforward assertions with simple cases,
assert probably will meet your needs. But if you ever outgrow
assert, you'll be better off with
chai or whatever. So we encourage people to start there. It's better for them (usually) and better for us (usually).
I hope this is helpful and answers your question.