I'm currently working on a component that looks like this:
@Component({
selector: 'my-form',
templateUrl: './my-form.component.html',
})
export class MyFormComponent implements OnInit {
@Input('company') company: CompanyInfo;
private config: ConfigInterface | null;
constructor(private companyService: CompanyService, private something: Something, private dialog: MatDialog) {
}
ngOnInit() {
....
}
theFunctionToBeTested(company: string) {
if (someTest.indexOf(domain)) {
this.dialog.open(MyAllertComponent, {
data: {
title: 'blah',
},
});
}
}
}
However, my unit test is not performing as expected:
describe( 'MyFormComp', () => {
it('should open MatDialog if email is from popular domain', () => {
const dialog = {} as MatDialog;
const comp = new MyComponent({} as CompanyService, {} as Something, dialog);
comp.getCompanys(company);
expect(dialog.open(AlertComponent));
});
})
And I'm receiving the following error message:
TypeError: dialog.open is not a function
I am aware of the reason behind this error - I need to mock the dialog properly for the open
function to work. Can someone guide me on how to achieve this using jasmine (i.e. how to correctly mock MatDialog?)
Since I am new to JavaScript unit testing, I would appreciate more specific guidance rather than just general keywords to search for.