Skip to content

Commit

Permalink
fix: cleanup components without id (#419)
Browse files Browse the repository at this point in the history
Closes #398
  • Loading branch information
timdeschryver committed Nov 14, 2023
1 parent db551f6 commit 523b8fd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions projects/testing-library/src/lib/testing-library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,10 @@ function cleanupAtFixture(fixture: ComponentFixture<any>) {

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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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: '<h1>My title</h1>',
// 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 {}

0 comments on commit 523b8fd

Please sign in to comment.