如何测试一个模块的运行程序段 [英] How to test run block of a module
本文介绍了如何测试一个模块的运行程序段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望我的AngularJS的应用程序,使HTTP请求从服务器获取用户信息或重定向到登录界面。我在应用程序的主模块的运行块中实现这一点。但我怎么测试在运行块中的code?或者我应该提出这个初始化code控制器中,使其可测试?我在写我的噶和Jasmine测试。
I want my AngularJS app to make a http request to retrieve user information from the server or redirect to login screen. I implemented this in a run block of my app's main module. But how do I test the code in a run block? Or should I move this initialization code in a controller to make it testable? I'm writing my tests with Karma and Jasmine.
任何帮助将是AP preciated!
Any help would be appreciated!
推荐答案
您可以通过模块的_runBlocks财产获得参考运行块。
You can get the reference to the run block via the _runBlocks property of the module.
与您的模块$ C $文件C:
The file with your module code:
angular.module('xmpl', []).
run(function() {
// some code here
});
测试套件:
var myModule = angular.module('xmpl'),
runBlock = myModule._runBlocks[0];
// Now can test the runBlock function according to your scenario
这篇关于如何测试一个模块的运行程序段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文