I've been struggling with writing unit tests that keep failing. Do you have any suggestions on the correct approach?
show(contactId: string, phoneNumber: string, contactType: string, section: string, memberId: string) {
this.$window.onbeforeunload = () => "";
$('.disabledcalldialog').on("click", e => {
this.$window.alert('Please close call dialog and try.');
e.preventDefault();
});
This is a snippet from my spec file:
beforeEach(() => {
inject(($rootScope: ng.IScope, $window) => {
spyOn($window, 'onbeforeunload');
$(window).trigger('onbeforeunload');
});
it('should be able to call when changing URL', () => {
expect($window.onbeforeunload).toHaveBeenCalled();
Karma keeps giving me an error message saying "TypeError: Unable to get property 'onbeforeunload' of undefined or null reference";