Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Closed
Pomax opened this issue Jan 9, 2025 · 3 comments
Closed

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

Pomax opened this issue Jan 9, 2025 · 3 comments

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

@koddsson
Copy link
Member

Sounds like this is resolved! Feel free to comment again/reopen if not @Pomax 👍🏻

@Pomax
Copy link
Author

Pomax commented Jan 22, 2025

I don't know if it's worth reopening over, but it would be nice if this advice were "easily" findable somewhere in the docs too, so that others won't end up filing a new issue again (as closed issues often don't surface on web searches etc)

@koddsson koddsson reopened this Jan 24, 2025
@chaijs chaijs locked and limited conversation to collaborators Jan 24, 2025
@koddsson koddsson converted this issue into discussion #1668 Jan 24, 2025

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants