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

Async support in core #1674

Open
43081j opened this issue Feb 19, 2025 · 0 comments
Open

Async support in core #1674

43081j opened this issue Feb 19, 2025 · 0 comments

Comments

@43081j
Copy link
Contributor

43081j commented Feb 19, 2025

We should add async support to the core. This means chai-as-promised will no longer be needed in most cases (but will still be useful if you prefer the style it uses).

This kind of API:

expect(val).resolves.to.equal(303);

expect(val).rejects.to.throw("error");

This is very similar to vitest's existing chai extension. So it is also possible we can remove a lot of code from vitest once this becomes stable in core.

A few notes of things we'd need to do:

  • All assertions would need to return a Promise<void> if the special flag is set
    • We can likely do this by wrapping all addMethod and addChainableMethod in something which conditionally awaits based on the special flag
  • The special flag would be something like flag(this, 'promise') or flag(this, 'isAsync')
  • A new resolves property would need to be added which sets the special flag
    • It would also need to set object to a new promise which, when resolved, sets object again to the resolved value
  • A new rejects property would need to be added which sets the special flag

cc @koddsson @keithamus

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

1 participant