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
TestBed should be zoneless compatible #48198
Comments
@yjaaidi thanks for submitting this ticket. The first step of making the The second step of exposing a config option would require some discussions within the team. I'll share an update once I have it. Thank you. |
Thanks @AndrewKushnir for your quick feedback. While investigating a bit further, I discovered another spot.
IMO, this shouldn't throw an error. The error doesn't make much sense if we're not using Then the function should actually be named something like |
@yjaaidi the mentioned call is likely coming from here: angular/packages/core/testing/src/test_hooks.ts Lines 34 to 42 in 4d398a0
We need to experiment with this more, but we can probably update it eventually to detect if we are in "zone-less" mode:
|
Thanks @AndrewKushnir ! In fact, this could be a quick win. If someone is using fakeAsync, the error is already thrown anyway. |
@yjaaidi could you please let me know which error you refer to? |
@AndrewKushnir it's this one: angular/packages/core/testing/src/fake_async.ts Lines 51 to 56 in 0ff5d97
|
In component tests, the angular/packages/core/test/application_ref_spec.ts Lines 610 to 613 in 4e098fa
Example import { ComponentFixtureNoNgZone, TestBed } from '@angular/core/testing'
import { MyComponent } from './my.component';
it('supports zoneless', () => {
TestBed.configureTestingModule({
providers: [
{ provide: ComponentFixtureNoNgZone, useValue: true },
],
});
const fixture = TestBed.createComponent(MyComponent);
}); The tests for angular/packages/core/test/component_fixture_spec.ts Lines 298 to 329 in 8c04fa7
The all but missing docs for |
Hey @LayZeeDK ! Thanks for the help! Actually, angular/packages/core/testing/src/test_bed_compiler.ts Lines 749 to 751 in 6948f0f
But then it's already too late as the constructor of angular/packages/core/src/zone/ng_zone.ts Lines 128 to 130 in 5e404d3
This made it mandatory to import But guess what! Thanks to your comment, I checked again and this was indirectly fixed by the new Thanks so much to both of you!!! Also thank you @AndrewKushnir ! and sorry for the delay... I was off for some time and still catching up. |
This was partially and indirectly solved by #49557 by @atscott Now, we still have to fix the clean up: #48198 (comment) |
The test hooks should not throw if applications choose not to load ZoneJS. fixes angular#48198
The test hooks should not throw if applications choose not to load ZoneJS. fixes angular#48198
The test hooks should not throw if applications choose not to load ZoneJS. fixes angular#48198
…lar#55096) The test hooks should not throw if applications choose not to load ZoneJS. fixes angular#48198 PR Close angular#55096
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. |
Which @angular/* package(s) are relevant/related to the feature request?
core
Description
TL;DR:
TestBed
should provide a way to run zoneless and avoid importingzone.js
when we don't need it.And I'd love to help with a PR?
TestBed
assumes thatzone.js
is available while there are contexts when this is not necessary and here are some examples:fixture.detectChanges()
These tests must load
zone.js
when they don't need it.While this might sound like a really minor issue, loading
zone.js
can cause trouble in some situations.For instance, integrating
TestBed
andzone.js
with vitest causes the following errorMethod Promise.prototype.then called on incompatible receiver
which is probably due tozone.js
patching promises and breaking Node.js's safe promises when importing ESMs dynamically or something like that. This is similar to the issue described here #47872.Proposed solution
A first quick win is replacing this:
angular/packages/core/testing/src/test_bed_compiler.ts
Lines 749 to 751 in 6948f0f
with:
this would then allow us to go zoneless with this configuration:
The main problem with this approach is the boilerplate and having to use the
ɵNoopNgZone
implementation detail.A second step would be adding the bootstrap's
ngZone
option toinitTestEnvironment
:Alternatives considered
Disable promises monkey patching using
globalThis.__Zone_disable_ZoneAwarePromise = true
but this causes the following issue #37349
Cf. #48359
The text was updated successfully, but these errors were encountered: