jest-community / vscode-jest

The optimal flow for Jest based testing in VS Code
MIT License
2.83k stars 290 forks source link

asyncError not caught causing failing tests to pass #894

Open marr opened 2 years ago

marr commented 2 years ago

Environment

  1. vscode-jest version: 4.6.0
  2. node -v: 16.16.0
  3. npm -v or yarn --version: npm 8.11.0
  4. npm ls jest or npm ls react-scripts (if you haven’t ejected): jest@28.1.3
  5. your vscode-jest settings if customized:
    • jest.jestCommandLine? npx jest
    • jest.autoRun? false
    • anything else that you think might be relevant? [fill]
  6. Operating system: osx 12.5

Prerequisite

Steps to Reproduce

https://github.com/marr/jest-async-fail

  1. npm install
  2. npx jest
  3. see failing test
  4. open in vs code with extension and run test
  5. see passing test

Relevant Debug Info

Screen Shot 2022-08-12 at 10 45 51 AM Screen Shot 2022-08-12 at 10 46 38 AM

This is blocking us from fully adopting/trusting the plugin at the moment. Some screenshots are included to potentially point out that within the jest runner for this test, asyncError is set to an Error object, but as you can see below things are green in the ide.

Screen Shot 2022-08-12 at 10 59 11 AM

Thanks for any help

connectdotz commented 2 years ago

@marr sorry for the late reply. Your repo helped us identify another bug (thanks), and we were able to address that, however not related to your actual issue.

Now that is out of the way, I played with your sample repo again today: the original repo (after uncommented the xdescribe), showed ERR_UNHANDLED_REJECTION:

node:internal/process/promises:246
          triggerUncaughtException(err, true /* fromPromise */);
          ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "Error: expect(received).resolves.toContain(expected) // indexOf

Expected value: 2
Received array: [1]".] {
  code: 'ERR_UNHANDLED_REJECTION'
}

So I modified your tests then all is well:

Screen Shot 2022-09-24 at 4 49 01 PM

The green check mark you saw in the TestExplorer is a cached status since the async error interfered with the proper update. It should do better, fortunately, this is addressed in the next release:

Screen Shot 2022-09-24 at 5 03 02 PM

Thanks for bringing this to our attention, hopefully after fixing your test code you are good to go.