Skip to content

console.assert() prints 'Assertion failed' when called with no arguments #34500

@ghost

Description

  • Version: 14.6.0
  • Platform: Darwin Kernel Version 19.5.0 root:xnu-6153.121.2~2/RELEASE_X86_64 x86_64
  • Subsystem: console

What steps will reproduce the bug?

  1. Create a file, e.g. index.js
  2. Add the following content:
console.assert();
  1. Run the file with the following command: node index.js
  2. Observe the console output: Assertion failed

How often does it reproduce? Is there a required condition?

Always. There are no specific conditions.

What is the expected behavior?

I guess it should not output anything in this case (or at least tell the user that they should specify an expression/value).
The typings provided by the lib.dom.d.ts (VS Code) specify that the assert method has the following signature:

assert(condition?: boolean, ...data: any[]): void;

Therefore, the value to be checked is optional -> we may not have it in place. Thus, we should handle this possibility.

Even if we do not take into account the TS typings, Node.js docs state as follows:

A simple assertion test that verifies whether value is truthy. If it is not, Assertion failed is logged. 

In the mentioned case we do not have any value to perform a check on, therefore, the result of the call is not entirely correct.

So, if the first argument that would be evaluated is an optional parameter, assert should not print any messages. So, we can handle this situation or at least do nothing in such situations. It seems to be compliant with the Console Standard#assert

Or at least we can add some kind of "warning" in the docs.

What do you see instead?

Console's output: Assertion failed

Additional information

Refs:

P.S. If this should be fixed, I would love to work on that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    consoleIssues and PRs related to the console subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions