如何进行unit testing以查看角度是否未定义?

我正在使用角度版本1和茉莉花进行unit testing。

我想做的测试是:

当我在ie7中加载index.html页面时,我加载了一个html横幅,说下载最新的浏览器。

我目前正在索引页面上使用JQuery加载一个html模板。

是否可以测试这个,因为它在角度app之外。

这是我在index.html页面上的当前代码:

      if(window.angular === undefined) $(function(){$("#angularNotSupportedModal").load("/app/noAngularModal.html");});    

任何建议都会很棒。

谢谢

任务缩小到良好的旧jQuery测试,这是乏味但可能的。 这取决于代码,如果jQuery可以只是间谍或应该完全存根和嘲笑。

应将测试的脚本隔离以分离要正确测试的function。 它可能是这样的:

 it('should call through $ chain', (done) => { var angular = window.angular; window.angular = undefined; spyOn(jQuery.prototype, 'ready').and.callThrough(); spyOn(jQuery.prototype, 'load').and.callThrough(); // make spy not break the chain var init = jQuery.prototype.init.bind(jQuery.prototype); spyOn(jQuery.prototype, 'init').and.callFake(init); window.runAngularNotSupportedFunction(); expect(jQuery.prototype.ready).toHaveBeenCalledWith(jasmine.any(Function)); expect(jQuery.prototype.init).toHaveBeenCalledWith('#angularNotSupportedModal', undefined); expect(jQuery.prototype.load).toHaveBeenCalledWith('/app/noAngularModal.html'); window.angular = angular; jQuery.ready.promise().done(done) })