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