I am writing a unit test for the method in a component that opens a mat-dialog. Tried writing the following unit test to make sure if the dialog opens. But I am getting an error.
component.ts:
It has the onupload method.
onUpload(event: FileUpload) {
this.Service
.get(event.id)
.subscribe((data: Data[]) => {
const dialogRef = this.dialog.open(
DialogComponent,
{data,}
);
dialogRef.afterClosed().subscribe({
next: (Id: string) => {
if (Id === null {
this.reset();
}
unittest.spec.ts:
describe('open()', () => {
it('should open the dialog', () => {
const testCases = [
{
returnValue: 'Successfully opens a dialog',
isSuccess: true
},
{
returnValue: 'cancel',
isSuccess: false
},
];
testCases.forEach(testCase => {
it(`should open the file upload matDialog `, () => {
const returnedVal = {
afterClosed: () => of(testCase.returnValue)
};
spyOn(component, 'reset');
spyOn(component['matDialog'], 'open').and.returnValue(returnedVal);
component.onUpload(new FileUpload(
'fid',
'oid',
));
if (testCase.isSuccess) {
expect(component.reset).toHaveBeenCalled();
} else {
expect(component.reset).not.toHaveBeenCalled();
}
expect(component['matDialog'].open).not.toHaveBeenCalled();
});
});
I am getting an error " 'mat-grid-tile' is not a known element: 1. If 'mat-grid-tile' is an Angular component, then verify that it is part of this module.". Please help. Thanks.