Skip to content

Commit 523b8fd

Browse files
fix: cleanup components without id (#419)
Closes #398
1 parent db551f6 commit 523b8fd

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

projects/testing-library/src/lib/testing-library.ts

+3
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,10 @@ function cleanupAtFixture(fixture: ComponentFixture<any>) {
492492

493493
if (!fixture.nativeElement.getAttribute('ng-version') && fixture.nativeElement.parentNode === document.body) {
494494
document.body.removeChild(fixture.nativeElement);
495+
} else if (!fixture.nativeElement.getAttribute('id') && document.body.children?.[0] === fixture.nativeElement) {
496+
document.body.removeChild(fixture.nativeElement);
495497
}
498+
496499
mountedFixtures.delete(fixture);
497500
}
498501

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Component } from '@angular/core';
2+
import { render, screen } from '../../src/public_api';
3+
4+
test('should create the app', async () => {
5+
await render(FixtureComponent);
6+
expect(screen.getByRole('heading')).toBeInTheDocument();
7+
});
8+
9+
test('should re-create the app', async () => {
10+
await render(FixtureComponent);
11+
expect(screen.getByRole('heading')).toBeInTheDocument();
12+
});
13+
14+
@Component({
15+
selector: 'atl-fixture',
16+
standalone: true,
17+
template: '<h1>My title</h1>',
18+
// eslint-disable-next-line @angular-eslint/no-host-metadata-property
19+
host: {
20+
// eslint-disable-next-line @typescript-eslint/naming-convention
21+
'[attr.id]': 'null', // this breaks the cleaning up of tests
22+
},
23+
})
24+
class FixtureComponent {}

0 commit comments

Comments
 (0)