I am trying to unit test this popup method but I cannot, can you please help
openPram(): void {
const dialogConfig = new MatDialogConfig();
this.dialog.open(ParamGameComponent, dialogConfig);
}
CodePudding user response:
Since there isn't a lot of code here and clarification on what you want to test. I am going to assume you want to test that dialog.open() is called with the params of ParamGameComponent and the dialogConfig const. If that is true then your test could look something like this:
it('open dialog test', () => {
const openDialogSpy = spyOn(component.dialog, 'open')
const fakeDialogConfig = new MatDialogConfig;
component.openPram();
expect(openDialogSpy).toHaveBeenCalledWith(ParamGameComponent,
fakeDialogConfig);
});
The component var in this test is assuming as well that you have the default Angular CLI generated spec.ts files that creates a local instance of the component you are writing tests for.