Skip to content

Async support in coreΒ #1674

@43081j

Description

@43081j

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions