Skip to content

Get pass/fail as return value rather than printing to stdout? #1668

Answered by 43081j
Pomax asked this question in Support
Discussion options

You must be logged in to vote

i think you would need to try/catch the assertion yourself

assertions throw by design just like in node:assert and similar

so you'd have to have a wrapper around it that does this:

function assertWithoutThrow(assertion) {
  try {
    assertion();
    return true;
  } catch {
    return false;
  }
}

assertWithoutThrow(() => {
  assert.ok(false);
});

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by koddsson
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #1661 on January 24, 2025 10:50.