Trying to confirm the functionality of the following method:
showSnackbar(): void {
if (this.modifiedReferences.length) {
const snackbar = this.snackbarService.open({
message: '',
type: 'success',
duration: 10000,
actionText: 'SHOW DETAILS'
});
snackbar.instance.actionClicked.subscribe(() => {
this.dialogService.modal(ModifiedComponent);
});
}
}
Here is the corresponding test scenario:
it('should trigger the showSnackbar method', () => {
const showSnackbarSpy: jasmine.Spy = spyOn(TestBed.inject(SnackbarService), 'open');
component.showSnackbar();
expect(showSnackbarSpy).toHaveBeenCalled();
});
An error is encountered during testing stating that it cannot read property 'instance' of undefined.