Prerequisites
Description
Error from afterEach hides the original error from the test case when retries is used (> 0).
Steps to Reproduce
Here is the minimum test case to reproduce the issue
describe('test after each error', () => {
afterEach(async () => {
throw new Error('Error from after each');
});
it('test one', async () => {
throw new Error('Error from test');
});
});
Then run the following to see the difference
npx mocha --retries 0 index.spec.js
npx mocha --retries 1 index.spec.js
Expected behavior: [What you expect to happen]
The result should tell me the error raised from the test case
npx mocha --retries 0 index.spec.js
test after each error
1) test one
2) "after each" hook for "test one"
0 passing (3ms)
2 failing
1) test after each error
test one:
Error: Error from test
at Context.<anonymous> (index.spec.js:8:11)
at process.processImmediate (node:internal/timers:476:21)
2) test after each error
"after each" hook for "test one":
Error: Error from after each
at Context.<anonymous> (index.spec.js:4:11)
at process.processImmediate (node:internal/timers:476:21)
Actual behavior: [What actually happens]
The output did not show the error raised in the test case but only show the error from the clean up afterEach
npx mocha --retries 1 index.spec.js
test after each error
1) "after each" hook for "test one"
0 passing (2ms)
1 failing
1) test after each error
"after each" hook for "test one":
Error: Error from after each
at Context.<anonymous> (index.spec.js:4:11)
at process.processImmediate (node:internal/timers:476:21)
Reproduces how often: [What percentage of the time does it reproduce?] 100%
Versions
- The output of
mocha --version and node_modules/.bin/mocha --version: 10.2.0 for both
- The output of
node --version: v18.16.1
- Your operating system
- name and version: OSX 13.5.1
- architecture (32 or 64-bit): 64
- Your shell (e.g., bash, zsh, PowerShell, cmd): iTerm
- Your browser and version (if running browser tests):
- Any third-party Mocha-related modules (and their versions):
- Any code transpiler (e.g., TypeScript, CoffeeScript, Babel) being used (and its version): No
Additional Information
Nothing
Prerequisites
faqlabelnode_modules/.bin/mocha --version(Local) andmocha --version(Global). We recommend that you not install Mocha globally.Description
Error from afterEach hides the original error from the test case when retries is used (> 0).
Steps to Reproduce
Here is the minimum test case to reproduce the issue
Then run the following to see the difference
Expected behavior: [What you expect to happen]
The result should tell me the error raised from the test case
Actual behavior: [What actually happens]
The output did not show the error raised in the test case but only show the error from the clean up
afterEachReproduces how often: [What percentage of the time does it reproduce?] 100%
Versions
mocha --versionandnode_modules/.bin/mocha --version: 10.2.0 for bothnode --version: v18.16.1Additional Information
Nothing