【发布时间】:2015-01-06 18:56:12
【问题描述】:
我正在使用 Karma 对 AngularJS 应用程序运行单元测试。问题是我使用了 ui-router 插件,它发出一些 XHR 请求来运行模板这一事实迫使我模拟这些请求。因此,我看到自己对每个测试文件都重复这个:
beforeEach(function($templateCache) {
$templateCache.put('templates/layout.html', '');
$templateCache.put('templates/dashboard/index.html', '');
$templateCache.put('templates/session/login.html', '');
});
如何为我的所有单元测试运行这段代码?我尝试谷歌搜索,但没有运气。另外,我应该以其他方式这样做吗?请分享您的意见。
谢谢大家。
【问题讨论】:
标签: angularjs unit-testing jasmine karma-runner karma-jasmine