{"record":{"id":"dd2297289b0b5b78","repo":"angular/components","slug":"mattestdialogopener-does-not-have-a-component-prov","errorCode":null,"errorMessage":"MatTestDialogOpener does not have a component provided.","messagePattern":"MatTestDialogOpener does not have a component provided\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/material/dialog/testing/dialog-opener.ts","lineNumber":52,"sourceCode":"  closedResult: R | undefined;\n\n  private readonly _afterClosedSubscription: Subscription;\n\n  private readonly _ngZone = inject(NgZone);\n\n  /** Static method that prepares this class to open the provided component. */\n  static withComponent<T = unknown, R = unknown>(\n    component: ComponentType<T>,\n    config?: MatDialogConfig,\n  ) {\n    MatTestDialogOpener.component = component;\n    MatTestDialogOpener.config = config;\n    return MatTestDialogOpener as ComponentType<MatTestDialogOpener<T, R>>;\n  }\n\n  constructor() {\n    if (!MatTestDialogOpener.component) {\n      throw new Error(`MatTestDialogOpener does not have a component provided.`);\n    }\n\n    this.dialogRef = this._ngZone.run(() => {\n      const config = {...(MatTestDialogOpener.config || {})};\n      config.enterAnimationDuration = 0;\n      config.exitAnimationDuration = 0;\n      return this.dialog.open<T, R>(MatTestDialogOpener.component as ComponentType<T>, config);\n    });\n    this._afterClosedSubscription = this.dialogRef.afterClosed().subscribe(result => {\n      this.closedResult = result;\n    });\n  }\n\n  ngOnDestroy() {\n    this._afterClosedSubscription.unsubscribe();\n    MatTestDialogOpener.component = undefined;\n    MatTestDialogOpener.config = undefined;\n  }","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/material/dialog/testing/dialog-opener.ts#L34-L70","documentation":"MatTestDialogOpener is a test utility injected as a dialog 'opener' component; its static component field must be configured via withComponent(...) before it is instantiated. The constructor throws if no dialog component class was provided, because it would otherwise have nothing to open. It guards against using the test opener without the static withComponent() setup call.","triggerScenarios":"Providing MatTestDialogOpener in a test module (e.g. via DialogTestModule or providers) without ever calling MatTestDialogOpener.withComponent(MyDialogComponent) beforehand; ordering issue where the injector instantiates the opener before withComponent runs; using the opener from a shared test module where another test reset configuration.","commonSituations":"Setting up dialog component harness tests and skipping the withComponent step; copying provider setup from docs but not the withComponent call; multiple beforeEach ordering problems causing the opener to be created before configuration.","solutions":["Call MatTestDialogOpener.withComponent(MyDialogContent) before providing/injecting the opener in the test","Use DialogTestModule.withDialogs(...) or the documented setup so withComponent is invoked during TestBed configuration","Ensure each test that injects the opener re-applies withComponent if configuration is reset between tests","Alternatively use DialogHarness directly instead of MatTestDialogOpener"],"exampleFix":"// before\nTestBed.configureTestingModule({ providers: [MatTestDialogOpener] });\nconst opener = TestBed.inject(MatTestDialogOpener);\n// after\nTestBed.configureTestingModule({\n  providers: [MatTestDialogOpener.withComponent(DialogContentComponent)],\n});\nconst opener = TestBed.inject(MatTestDialogOpener);","handlingStrategy":"validation","validationCode":"if (!MatTestDialogOpener.component) {\n  throw new Error('Call MatTestDialogOpener.withComponent(MyDialogComponent) before injecting the opener');\n}\nconst opener = TestBed.inject(MatTestDialogOpener);","typeGuard":null,"tryCatchPattern":"try {\n  opener = TestBed.inject(MatTestDialogOpener);\n} catch (e) {\n  if (String(e?.message).includes('does not have a component provided')) {\n    fail('MatTestDialogOpener.withComponent() was not called in TestBed setup');\n  }\n  throw e;\n}","preventionTips":["Always configure via MatTestDialogOpener.withComponent(...) (or DialogTestModule) in TestBed providers, not after","Call withComponent inside TestBed.configureTestingModule so setup order is guaranteed","Reset/re-apply configuration in beforeEach if tests mutate the static config","Prefer the newer Dialog test harness APIs that do not require static configuration"],"tags":["angular","testing","dialog","component-harness"],"backgroundTag":"missing-component-configuration","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}