【发布时间】:2015-11-07 23:02:36
【问题描述】:
我正在尝试编写一些单元测试,但它们失败了。你能建议我正确的做法吗?
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: Unable to get property 'onbeforeunload' of undefined or null reference”;
【问题讨论】:
标签: javascript angularjs unit-testing frontend karma-jasmine