我正在尝试编写一些单元测试,但它们一直失败。你能建议一下正确的做法吗?
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();
});
我的规范文件如下:
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抛出错误信息,如“TypeError:无法获取未定义或空引用的属性'onbeforeunload'”;