Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.4K
Views
ERROR NullInjectorError: R3InjectorError(DynamicTestModule)[KDSDialogService -> MatDialog -> MatDialog]: NullInjectorError: No hay proveedor para MatDialog

Estoy haciendo pruebas unitarias en mi aplicación. Soy nuevo en las pruebas, así que necesito su ayuda.

En mi aplicación hago un servicio que usa MatDialog (KDSDialogService). He intentado poner muchas alternativas de importación, mi servicio o matdialog como proveedores, no tengo idea de qué hacer.

 export declare class KDSDialogService { dialog: MatDialog; private dialogRef; constructor(dialog: MatDialog); open(componentOrTemplateRef: ComponentType<any> | TemplateRef<any>, title?: string, data?: any, size?: DialogSize, showClose?: boolean): MatDialogRef<any, any>; static ɵfac: ɵngcc0.ɵɵFactoryDef<KDSDialogService, never>; }

Y en mi home.component.spec importo y hago las declaraciones aquí, pero sigo recibiendo este error.

 describe('HomeComponent', () => { let component: HomeComponent; let fixture: ComponentFixture<HomeComponent>; beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [HomeComponent ], imports:[KDSDialogService, MatDialogModule], }).compileComponents(); })); beforeEach(() => { fixture = TestBed.createComponent(HomeComponent); component = fixture.componentInstance; }); it('should create', () => { fixture.detectChanges(); expect(component).toBeTruthy(); }); });

Impresión del error

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Puedes burlarte de esta manera:

 import { MatDialog } from '@angular/material/dialog'; //... let matDialogService: jasmine.SpyObj<MatDialog>; matDialogService = jasmine.createSpyObj<MatDialog>('MatDialog', ['open']); TestBed.configureTestingModule({ providers: [ { provide: MatDialog, useValue: matDialogService, },
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!