如何进行单元测试以查看角度是否未定义
How can I do a unit test to see if angular is undefined?
我在单元测试中使用了带有jasmine的angular版本1。
我想做的测试是:
例如,当我在ie7中加载index.html页面时,我会加载一个html横幅,上面写着下载最新的浏览器。
我目前正在索引页面上使用JQuery加载一个html模板。
有没有可能测试一下,因为它在angular应用程序之外。
这是我在index.html页面上的当前代码:
<!doctype html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<base href="/app/" />
<!-- Is Angular supported -->
<script>
if(window.angular === undefined)
$(function(){$("#angularNotSupportedModal").load("/app/noAngularModal.html");});
</script>
</head>
<body ng-app="app" ng-cloak>
<div id="angularNotSupportedModal"></div>
<div ui-view></div>
<!-- Application -->
<script src="/scripts/app.js"></script>
<!-- Config -->
<script src="/scripts/config.js"></script>
</body>
</html>
任何建议都很好。
感谢
任务缩小到优秀的旧jQuery测试,这很乏味,但也是可能的。这取决于代码,jQuery
是否可以被监视,或者应该被完全清除和嘲笑。
测试的脚本应该被隔离,以分离要正确测试的函数。它可能是这样的:
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)
})
相关文章:
- 检查对象的所有属性是否未定义
- AngularJs 检查是否未定义和空的最佳实践
- 离子警报 - 检查结果是否未定义
- 什么更快?运行空函数或检查函数是否未定义
- Jquery Ajax 和 Json:如何检查是否未定义
- 函数返回undefine,即使我在返回之前检查了变量是否未定义
- 在执行脚本之前,请查看对象是否未定义
- 如何进行单元测试以查看角度是否未定义
- 为什么我无法检查对象节点是否未定义
- 检查变量是否未定义不起作用
- 如何检查评估名称是否未定义
- 使用挖空检查是否未定义
- 时间微调器检查是否未定义不起作用
- 检查在.ech()内部使用jQuery.find()时是否未定义
- 检查两个变量是否未定义
- ReferenceError: Can't find variable: google"检查是否未定义
- 检查对象参数是否未定义
- 为什么这个检查抛出错误,即使我事先检查了它是否未定义
- 如何检查文字中的属性是否未定义
- 如何检查元素是否未定义