Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Pomax opened this issue Jan 9, 2025 · 1 comment
Open

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

Pomax opened this issue Jan 9, 2025 · 1 comment

Comments

@Pomax
Copy link

Pomax commented Jan 9, 2025

Is there a way to get chai to simply return a true/false rather than printing anything to the console? I had a look at the docs on the website but couldn't find anything obvious about configuring chai's behaviour.

(And if there is, could that be added as a section on the "getting started" part of the site?)

@43081j
Copy link
Contributor

43081j commented Jan 9, 2025

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);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants