Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Tests are not isolated when overriding a deferred component and aot is set to true true #61229

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

Open
JeanMeche opened this issue May 8, 2025 · 0 comments
Labels
area: testing Issues related to Angular testing features, such as TestBed core: defer Issues related to @defer blocks.
Milestone

Comments

@JeanMeche
Copy link
Member

JeanMeche commented May 8, 2025

When the unit tests are run with the aot: true option.
Overrides on deferred componenents have side effects on others tests.

Repro : https://stackblitz.com/edit/angular-defer-test-compile?file=src%2Fapp%2Fapp.spec.ts

This test has no override, but it suffers from the side effects of the following one.

  it('should render deferred', async () => {
    // This test suffers from the override in the other test cases.
    const fixture = TestBed.createComponent(App);

    expect(fixture.nativeElement.innerText).toBe('App');
    fixture.detectChanges();

    const componentFixture = TestBed.createComponent(App);
    const deferBlockFixture = (await componentFixture.getDeferBlocks())[0];
    await deferBlockFixture.render(DeferBlockState.Complete);

    expect(fixture.nativeElement.innerText).toBe('App Foooo');
  });

The following test overrides the template of Foo, the deferred component.

  // This test impacts the 1st test case. 
  it('should render deferred with override', async () => {
    // Overriding the deferred component
    TestBed.overrideComponent(Foo, {
      set: { template: 'bar' },
    });

    const fixture = TestBed.createComponent(App);
    fixture.detectChanges();

    const componentFixture = TestBed.createComponent(App);
    const deferBlockFixture = (await componentFixture.getDeferBlocks())[0];
    await deferBlockFixture.render(DeferBlockState.Complete);

    expect(fixture.nativeElement.innerText).toBe('App bar');
    console.log(App);
  });

Unit test repro

@JeanMeche JeanMeche added area: testing Issues related to Angular testing features, such as TestBed core: defer Issues related to @defer blocks. labels May 8, 2025
@ngbot ngbot bot modified the milestone: needsTriage May 8, 2025
@JeanMeche JeanMeche changed the title Tests are not isolated when overriding a deferred component and aot is set to true true in test target Tests are not isolated when overriding a deferred component and aot is set to true true May 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: testing Issues related to Angular testing features, such as TestBed core: defer Issues related to @defer blocks.
Projects
None yet
Development

No branches or pull requests

1 participant