0

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
1
  • Have you tried using assert.strictEqual(actual, expected[, message]) instead? I'm not sure it'll make a difference but it's worth a try Commented Dec 10, 2015 at 13:47

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

2 Comments

Doesn't work like that for me with node v4.2.3 (the current LTS)
What output are you getting if you run assert(false, 'hello world') in the node repl? It should be something like this i.imgur.com/ElLmW0U.png. That was using v4.2.3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.