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
bug(cdk/overlay): incompatible to non-jasmine environment in testing #22926
Comments
For what it's worth, this was meant as a temporary solution until angular/angular#18831 is resolved and we can use |
We have some logic in the overlay container that tries to prevent overlays from leaking between tests. The logic is currently limited to Jasmine tests and it happened to work by accident for Jest. Jest has made some changes that will break our check so these changes rework the logic to detect Jest and Mocha correctly. Fixes angular#22926.
We have some logic in the overlay container that tries to prevent overlays from leaking between tests. The logic is currently limited to Jasmine tests and it happened to work by accident for Jest. Jest has made some changes that will break our check so these changes rework the logic to detect Jest and Mocha correctly. Fixes #22926.
We have some logic in the overlay container that tries to prevent overlays from leaking between tests. The logic is currently limited to Jasmine tests and it happened to work by accident for Jest. Jest has made some changes that will break our check so these changes rework the logic to detect Jest and Mocha correctly. Fixes #22926. (cherry picked from commit 3f26e99)
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Overlay is not supporting a testing environment that is not Jasmine-compatible.
See
components/src/cdk/overlay/overlay-container.ts
Lines 17 to 18 in a4043f4
The
isTestEnvironment
flag must be true for the Overlay to be set up and tear down correctly in the test environment. This flag will only be true when running on Karma or using the Jasmine test runner.This is unfriendly for users who use a testing tool like Jest to test Angular. Actually, until Jest v26, the default test runner was
jest-jasmine2
, which is a Jasmine compatible runner, soisTestEnvironment
was true even for Jest. However, since Jest 27, the default test runner was changed tojest-circus
, which is not Jasmine compatible, so testing of components using Overlay will fail.Reproduction
Steps to reproduce:
yarn test:jasmine2
and it will be ok.yarn test:circus
and it will fail.The broken spec is below:
https://github.com/lacolaco/jest-cdk-sandbox/blob/cd65898cb907a549005e4214359fda1c12ebf179/src/app/app.component.spec.ts#L21-L33
As evidence to support this hypothesis, if I forge
window.jasmine
in Jest setup and pretend to be a Jasmine runner as the following workaround, this test will succeed. So this problem is not a problem with the internal workings of the new test runner, but simply a problem with the Overlay environment detection.https://github.com/lacolaco/jest-cdk-sandbox/blob/cd65898cb907a549005e4214359fda1c12ebf179/src/setup-jest.ts#L3-L10
Expected Behavior
Keeping the same behavior as the Jasmine environment.
Actual Behavior
yarn test:circus
only fails.Environment
The text was updated successfully, but these errors were encountered: