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

Feature: ability to add async matchers using expect.extend #4223

Closed
danrr opened this issue Aug 9, 2017 · 6 comments
Closed

Feature: ability to add async matchers using expect.extend #4223

danrr opened this issue Aug 9, 2017 · 6 comments

Comments

@danrr
Copy link

danrr commented Aug 9, 2017

Do you want to request a feature or report a bug?
Feature

What is the current behavior?
A custom matcher add using expect.extend needs to synchronously return an object containing pass and message fields.

What is the expected behavior?
Allow async functions to be used as matchers that return a promise which eventually resolves to an object containing pass and message. These would be subject to the usual timeout.

My use case would be to execute async operations on a custom snapshot inside the matcher in a way that's transparent to the user.

@danrr danrr changed the title Feature: ability to add async matcher susing expect.extend Feature: ability to add async matchers using expect.extend Aug 9, 2017
@cpojer
Copy link
Member

cpojer commented Aug 9, 2017

This seems quite complex, I don't think we'll be adding this at this time. You can already use expect(…).resolves.to<Matcher>() to simplify working with async data. Matchers expect to be executed synchronously and async operations can be wrapped around them using Promises.

@cpojer cpojer closed this as completed Aug 9, 2017
@danrr
Copy link
Author

danrr commented Aug 9, 2017

That's not quite the use case here.

expect would be passed stuff that's sync and the async stuff needs to happen after .resolves would have done anything.

@entropitor
Copy link

I also would want this if possible. The problem is that I want to abstract away some test logic into a custom jest matcher. However, unfortunately, some API's that I need to use return promises, so I cannot possibly make it a sync matcher

@dowsanjack
Copy link

This would actually be useful for me and my team as well. Does someone has any plans to implement this?

@SimenB
Copy link
Member

SimenB commented Jan 22, 2018

If you can provide a PR which is not super complex, we might be able to merge it. No guarantees, though.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants