-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Description
🐛 Bug Report
The problem is that I need to distinguish scopes on every beforeAll
and beforeEach
call.
However, adding a listener on addEventHandler
doesn't bring the desired effect, because the listener is added to a different context and hasn't been ever called.
With jasmine
it was quite easy:
jasmine.getEnv().addReporter(reporterStack);
And would be great to have the same behavior in jest-circus
.
To Reproduce
This is the test and desired code: https://github.com/satanTime/jest-circus-hooks/blob/master/src/app/app.component.spec.ts#L7-L21
Steps to reproduce the behavior:
- clone https://github.com/satanTime/jest-circus-hooks
- npm install
- npm run test
- failure
> jest -w 1 --config jest.js
FAIL src/app/app.component.spec.ts
main block
✕ uses listener (2 ms)
sub block
✓ simulates positive (3 ms)
- edit
jest.ts
and uncommenttestRunner: 'jest-jasmine2',
- npm run test
- no failure
This is the place I want to add my callback to.
https://github.com/facebook/jest/blob/master/packages/jest-circus/src/state.ts#L14
Expected behavior
addEventHandler
register a callback properly and the callback is triggered on events.
For example, when I change the source code in node_modules
to:
const eventHandlers = window.eventHandlers || [_eventHandler.default, _formatNodeAssertErrors.default];
window.eventHandlers = eventHandlers;
it works correctly.
Proposed PR with a fix
The PR is here #11529
envinfo
System:
OS: macOS 11.4
CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Binaries:
Node: 12.22.1 - /opt/local/bin/node
Yarn: 1.22.10 - /opt/local/bin/yarn
npm: 6.14.13 - /opt/local/bin/npm
npmPackages:
jest: 27.0.3 => 27.0.3