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

Return received results in Promise matchers #3508

Closed
nickserv opened this issue May 7, 2017 · 2 comments
Closed

Return received results in Promise matchers #3508

nickserv opened this issue May 7, 2017 · 2 comments

Comments

@nickserv
Copy link
Contributor

nickserv commented May 7, 2017

See #3068.

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

Feature request and/or unexpected behavior

What is the current behavior?

While the new resolves and rejects flags naturally pass Promise values/errors to their matchers, the matchers themselves don't return Promises that resolve with the value of their received Promise. If it's possible to implement, this feature would be useful for chaining expectations for the same async value.

If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install and yarn test.

test('Return received results in Promise matchers', async () => {
  const received = await expect(Promise.resolve(true)).resolves.toBeTruthy()
  return expect(received).toBeTruthy()
})
 FAIL  test.js
  ● Return received results in Promise matchers

    expect(received).toBeTruthy()
    
    Expected value to be truthy, instead received
      undefined

What is the expected behavior?

The test would pass if this was implemented. A workaround is to save the value to an awaited variable and avoid resolves/rejects.

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.

[email protected]

@cpojer
Copy link
Member

cpojer commented May 11, 2017

I prefer not to support chaining for now. The workaround sounds good to me; if you need the values multiple times, I recommend calling await on the actual thing rather than the matcher.

@cpojer cpojer closed this as completed May 11, 2017
@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.
Projects
None yet
Development

No branches or pull requests

3 participants