【发布时间】:2015-05-22 19:13:06
【问题描述】:
我有一个文件run.js,其中包含:
window.map.run([
'$rootScope', '$location', 'cache', 'userCache',
function($rootScope, $location, cache, userCache) {
userCache.checkSession().then(function(result) {
if(result.userId) {
cache.set('login', 'successfulLogin', true);
if($location.path() !== '/patients') {
$location.path('/patients');
}
}
});
}
]);
这会在应用加载时运行。这通常是很好的行为。但是当我对控制器进行单元测试时,一切都乱套了。我不知道如何spy 或mock 这是错误的。有什么想法吗?
谢谢!
【问题讨论】:
-
您可以将您的应用程序分解为多个角度模块。将 run 块放在根模块上,只加载单元测试中需要的子模块
标签: javascript angularjs unit-testing karma-runner