diff --git a/projects/testing-library/src/lib/testing-library.ts b/projects/testing-library/src/lib/testing-library.ts index 48af2d5..65932fc 100644 --- a/projects/testing-library/src/lib/testing-library.ts +++ b/projects/testing-library/src/lib/testing-library.ts @@ -492,7 +492,10 @@ function cleanupAtFixture(fixture: ComponentFixture) { if (!fixture.nativeElement.getAttribute('ng-version') && fixture.nativeElement.parentNode === document.body) { document.body.removeChild(fixture.nativeElement); + } else if (!fixture.nativeElement.getAttribute('id') && document.body.children?.[0] === fixture.nativeElement) { + document.body.removeChild(fixture.nativeElement); } + mountedFixtures.delete(fixture); } diff --git a/projects/testing-library/tests/issues/issue-398-component-without-host-id.spec.ts b/projects/testing-library/tests/issues/issue-398-component-without-host-id.spec.ts new file mode 100644 index 0000000..4508d64 --- /dev/null +++ b/projects/testing-library/tests/issues/issue-398-component-without-host-id.spec.ts @@ -0,0 +1,24 @@ +import { Component } from '@angular/core'; +import { render, screen } from '../../src/public_api'; + +test('should create the app', async () => { + await render(FixtureComponent); + expect(screen.getByRole('heading')).toBeInTheDocument(); +}); + +test('should re-create the app', async () => { + await render(FixtureComponent); + expect(screen.getByRole('heading')).toBeInTheDocument(); +}); + +@Component({ + selector: 'atl-fixture', + standalone: true, + template: '

My title

', + // eslint-disable-next-line @angular-eslint/no-host-metadata-property + host: { + // eslint-disable-next-line @typescript-eslint/naming-convention + '[attr.id]': 'null', // this breaks the cleaning up of tests + }, +}) +class FixtureComponent {}