Paulius Liekis
Paulius Liekis

Reputation: 1730

Jest marks test as success even if there was an assert

How to make this sort of test fail in Jest? Is there a global setting for making any test with a failed-assert fail in Jest?

test('Assert', () =>
{
    console.assert(false, "This should fail the test");
});

Upvotes: 0

Views: 676

Answers (1)

MatthewG
MatthewG

Reputation: 9303

This issue has been discussed here: https://github.com/facebook/jest/issues/5634

The suggestions include checking your environment or node version. If that doesn't work, you can add the following to your test setup file:

console.assert = (statement, message) => {
   if (!statement) throw new Error(message);
};

Upvotes: 1

Related Questions