feat(material/dialog): Make MatTestDialogOpener better
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 35/100
- Issue-Typ
- Feature
- Klarheit
- Muss geklärt werden
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- angular, typescript
- Bereich
- testing
Rechercherichtung
Start with MatTestDialogOpener and the existing dialog-opener.spec.ts, then read the referenced OverlayContainer implementation and its testing-overlay comments. Investigate how fixture querying, harness loading, and afterClosed handling currently work. Done should provide a defined, tested approach that makes dialog content queryable from the fixture and simplifies checking the closing result.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Feature Description
There's currently no supported way to render an overlay (and therefore a MatDialog) inside a component fixture during unit tests. Because overlays are attached to an OverlayContainer appended to document.body, they live outside the fixture's root element, which means:
fixture.debugElement.query(...) finds nothing inside the dialog.
Loading harnesses requires TestbedHarnessEnvironment.documentRootLoader rather than the standard fixture loader.
Asserting on dialog content requires reaching back to the document, e.g. getDebugNode(document.body) as DebugElement.
MatTestDialogOpener helps instantiate a dialog-hosted component (and removes the boilerplate of manually providing MatDialogRef + MAT_DIALOG_DATA mocks), but it doesn't address querying, and testing the close result still needs a manual async flush.
I prototyped a custom OverlayContainer that appends the container into the DOM, but it expects the fixture to be the first element in body:
import { OverlayContainer } from "@angular/cdk/overlay";
import { Injectable, Provider } from "@angular/core";
@Injectable()
export class FixtureOverlayContainer extends OverlayContainer {
protected override _createContainer(): void {
super._createContainer();
document.body.children[0].appendChild(this._containerElement);
}
}
export function provideFixtureOverlayContainer(): Provider[] {
return [{
provide: OverlayContainer,
useClass: FixtureOverlayContainer
}]
}
providing it in the test environment removes the need of documentRootLoader, the "simple" loader is enough, but querying the fixture still finds nothing. I found some comments about testing overlay plans I expect it could be useful in this case.
MatTestDialogOpener helps with creating the component, but testing the closing result still requires a manual await step, like
await firstValueFrom(fixture.componentInstance.dialogRef.afterClosed());. I found in the dialog-opener.spec.ts a setTimeout is awaited, there could be an async method baked into the MatTestDialogOpener class.
It would be really nice, if there would be a TestOverlay which creates the dialog in the fixture, so no const bodyDebug = getDebugNode(document.body) as DebugElement; is needed for querying components inside the dialog. Or at least have some methods getting the debugElement of the newly created component.
Use Case
Make testing components meant to be used inside MatDialogs more convenient, not like this
- Vorherrschende Sprache
- TypeScript
- Sterne
- 25k
- Forks
- 6.8k
- Ø Merge
- 1 T. 12 Std.
- Gemergte PRs (30 T.)
- 92
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus angular/components
-
bug(material/sort): hover hint arrow on an unsorted header shows the active sort direction, not the resulting direction after click.Evtl. vergeben @lekhmanrus hat das vor 4 Tagen übernommen. Offenarea: material/sort gemini-triaged needs triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
angular/components#33933 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug(mat-date-picker): month shown twice in date pickerEvtl. vergeben @PreethiPantangi hat das vor 21 Tagen übernommen. Offenarea: material/datepicker P4
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
angular/components#33763 · 2 Kommentare · 3 Reaktionen ·
Maintainer antworten meist innerhalb von 1 Tag
-
Bug in table.scss footer cell height: unset instead of footer row height unsetEvtl. vergeben @minwookshin hat das vor 8 Tagen übernommen. Offenarea: material/table P4
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
angular/components#33709 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
docs-bug(Table): Add example with `rowspan`Evtl. vergeben @BHUVANSH855 hat das vor 89 Tagen übernommen. Offenarea: material/table docs P4
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
angular/components#33455 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug(date-adapter): Misleading JSDoc for createDate returns typeEvtl. vergeben @BHUVANSH855 hat das vor 138 Tagen übernommen. Offenarea: material/core P3
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 78/100
angular/components#33059 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in angular/components
Ähnliche Issues
-
./collections should export setUmbracoVersion and setAllowFilePathUploads for in-process consumersOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
umbraco/Umbraco-CMS-MCP-Dev#563 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
-
afk-ok area:data-quality importer size:S
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 77/100
enorm-labs/event-junkie#3166 ·
Maintainer antworten meist innerhalb von 1 Tag
-
enhancement
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 80/100
alunduil/projects-v2-sync#21 ·