lukeed / lukeed/uvu

Throwing from test.after.each() makes otherwise failing test pass

Open
#201 1 comment 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
3k
Forks
101
PR merge metrics
No merged PRs in 30d

Description

So this had me scratching my head for a while today.

The following fails as expected:

```js
import { test } from 'uvu'

function ouch () {
throw new Error('Oops!')
}

test('two wrongs do not make a right', async (context) => {
ouch()
})

test.run()
```

Result:

```
❯ node index.mjs

✘ (0 / 1)

FAIL "two wrongs do not make a right"
Oops!

at ouch (file:///home/aral/sandbox/uvu-test/index.mjs:4:9)
at Object.handler (file:///home/aral/sandbox/uvu-test/index.mjs:12:3)
at Number.runner (file:///home/aral/sandbox/uvu-test/node_modules/uvu/dist/index.mjs:77:16)
at Timeout.exec [as _onTimeout] (file:///home/aral/sandbox/uvu-test/node_modules/uvu/dist/index.mjs:138:39)

Total: 1
Passed: 0
Skipped: 0
Duration: 1.60ms
```

However, if you add an `after.each()` method that itself throws, the test run doesn’t fail (exits with a success status and without showing the error):

```js
import { test } from 'uvu'

function ouch () {
throw new Error('Oops!')
}

test.after.each(() => {
throw new Error('The sky is falling.')
})

test('two wrongs do not make a right', async (context) => {
ouch()
})

test.run()
```

Result:

```
❯ node index.mjs

(0 / 1)

Total: 1
Passed: 0
Skipped: 0
Duration: 1.03ms
```

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduced example in index.mjs and the test.after.each() entry point. Run node index.mjs with and without the after.each hook to compare the reported result and exit status. Done means a throwing after.each hook no longer hides the failing test or produces a successful run.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.