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

Resolves and rejects matchers don't have source files in stack traces #4628

Closed
nickserv opened this issue Oct 8, 2017 · 4 comments
Closed
Labels

Comments

@nickserv
Copy link
Contributor

nickserv commented Oct 8, 2017

Do you want to request a feature or report a bug?
Either a bug or a missing feature for resolves and rejects.

What is the current behavior?
When resolves or rejects are used, stack traces only include stack frames internal to expect, Jest, and Node, not the source files that caused the error.

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.
Use the expect(...).resolves or .rejects syntax, either returning the expression or using an async function with await before expect. This issue can be avoided by using async functions without resolves/rejects, which I'm currently using as a workaround.

Unhelpful stack trace with resolves/rejects:

test('script with fixed version', async () => {
  const url = `https://unpkg.com/${name}@${version}/index.js`
  await expect(cdnm.updateDependency(createScript(url))).resolves.toEqual(createScript(replaceVersion(url)))
})

screen shot 2017-10-08 at 2 46 05 pm

Helpful stack trace without resolves/rejects:

test('script with fixed version', async () => {
  const url = `https://unpkg.com/${name}@${version}/index.js`
  expect(await cdnm.updateDependency(createScript(url))).toEqual(createScript(replaceVersion(url)))
})

screen shot 2017-10-08 at 2 46 31 pm

What is the expected behavior?
Stack frames should ideally include my source files because the error originates from my source files (it's not internal to Jest). This happens if I avoid resolves and rejects by using async functions or testing code that doesn't use Promises at all.

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

  • Jest 21.2.1
  • Node 8.6.0
  • npm 5.4.2
  • macOS 10.13
@thymikee
Copy link
Collaborator

Tested on Node 8.7.0, same Jest version and stack trace shows the test file like usual. Can you reproduce this on other Node versions?

@thymikee
Copy link
Collaborator

Ok, actually was able to reproduce it:

test('async reject no stack', async () => {
  await expect(Promise.resolve('test')).resolves.toEqual('tost');
});

produces:

at Object.<anonymous> (../jest/node_modules/expect/build/index.js:139:54)
          at Generator.next (<anonymous>)
          at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:188:7)

@SimenB
Copy link
Member

SimenB commented Jan 13, 2018

I'll merge this into #5104.

@SimenB SimenB closed this as completed Jan 13, 2018
@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
Projects
None yet
Development

No branches or pull requests

3 participants