I am using material dialog in angular and writing test to test close of the dialog I am getting error Expected a spy, but got undefined. Getting error in test fit('should call the function to close the dialog'
describe('XYZDetailsComponent', () => {
let component: XYZDetailsComponent;
let fixture: ComponentFixture<XYZDetailsComponent>;
const data = {
ip: '1.1.1.1',
name: 'test'
}
const setupComponent = () => {
fixture = TestBed.createComponent(XYZDetailsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
};
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule, MatDialogModule ],
declarations: [XYZDetailsComponent],
providers: [
{ provide: MatDialogRef, useFactory: () => jasmine.createSpyObj('MatDialogRef', ['close', 'afterClosed']) },
{provide: MAT_DIALOG_DATA, useValue: data},
]
})
.compileComponents();
});
it('should create', () => {
setupComponent();
expect(component).toBeTruthy();
});
fit('should call the function to close the dialog', () => {
setupComponent();
component.onNoClick();
expect(component.dialogRef.close()).toHaveBeenCalled();
});
});