Andrea Casaccia
Andrea Casaccia

Reputation: 4971

Node.js assert module: message parameter meaning

Reading Node.js assert's module documentation I have been failing to understand what is the meaning of the message parameter and how should I use it.

If I write an assertion like:

assert(container.search('asd') === undefined, "Can't find [asd]");

When runnning the code, if it fails, I just get an exception at the assertion line, and can't see the message:

assert.js:86
  throw new assert.AssertionError({
        ^
AssertionError: false == true
    at Object.<anonymous> (c:\tests\Container.js:70:1)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3

Upvotes: 0

Views: 207

Answers (1)

Jordan Adams
Jordan Adams

Reputation: 434

The message argument simply defines what the error message will be if the test fails. This is common across most assertion libraries.

Example:

assert(false, 'hello world')

throws the error

AssertionError: hello world

Upvotes: 1

Related Questions