【发布时间】:2015-04-02 15:59:57
【问题描述】:
我对单元测试比较陌生,但现在的任务是为我非常熟悉的现有代码库编写测试。
遗憾的是,我无法取得任何进展,也无法找到真正有用的文档。
代码库的主要组件是从 api 检索数据的服务,但我无法获取该服务所属模块的实例:
TypeError: module is not a function in /home/faebser/workspace/GridSense-CMS-App/dev/test/unit/api.test.js (line 13)
业力配置:http://sprunge.us/ObSP?js
业力输出:http://sprunge.us/WYHI?bash
有什么问题?为什么我无法获取模块的实例?
更新1:
我设法通过重新安装相同版本的角度和角度模拟来加载我的模块。但是现在我遇到了以下错误:
minErr/<@/home/faebser/workspace/GridSense-CMS-App/dev/bower_components/angular/angular.js:63:12
loadModules/<@/home/faebser/workspace/GridSense-CMS-App/dev/bower_components/angular/angular.js:4138:15
forEach@/home/faebser/workspace/GridSense-CMS-App/dev/bower_components/angular/angular.js:323:11
loadModules@/home/faebser/workspace/GridSense-CMS-App/dev/bower_components/angular/angular.js:4099:5
createInjector@/home/faebser/workspace/GridSense-CMS-App/dev/bower_components/angular/angular.js:4025:11
workFn@/home/faebser/workspace/GridSense-CMS-App/dev/bower_components/angular-mocks/angular-mocks.js:2425:44
我设法将错误追踪到以下几点:
"[$injector:modulerr] Failed to instantiate module ui.router due to:[$injector:nomod] Module 'ui.router' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.http://errors.angularjs.org/1.3.15/$injector/nomod?p0=ui.routerminErr/<@http://localhost:9876/base/bower_components/angular/angular.js:63:12module/<@http://localhost:9876/base/bower_components/angular/angular.js:1774:1ensure@http://localhost:9876/base/bower_components/angular/angular.js:1698:38module@http://localhost:9876/base/bower_components/angular/angular.js:1772:1loadModules/<@http://localhost:9876/base/bower_components/angular/angular.js:4115:22forEach@http://localhost:9876/base/bower_components/angular/angular.js:323:11loadModules@http://localhost:9876/base/bower_components/angular/angular.js:4099:5loadModules/<@http://localhost:9876/base/bower_components/angular/angular.js:4116:40forEach@http://localho"
好的,只是忘记在 karma-config 中添加 ui-router。
【问题讨论】:
标签: angularjs unit-testing jasmine karma-runner