这是我的模块:
// app.module.js
angular.module('app', ['firebase']);
我已经配置了这样的业力:
// karma.conf.js
files: [
'bower_components/angular/angular.js',
'bower_components/firebase/firebase.js',
'bower_components/angular-mocks/angular-mocks.js',
'src/**/*.js'
],
这是我的测试:
// data.service.spec.js
describe('dataservice', function () {
var dataservice;
beforeEach(module('app'));
beforeEach(function () {
inject(function (_dataservice_) {
dataservice = _dataservice_;
});
});
describe('getData()', function () {
it('should return an object', function () {
expect(typeof dataservice.getData()).to.equal('object');
});
});
});
" karma start -log-level DEBUG"我收到错误:
PhantomJS 2.1.1 (Linux 0.0.0) dataservice "before each" hook for "should return an object" FAILED
[$injector:modulerr] Failed to instantiate module app due to:
[$injector:modulerr] Failed to instantiate module fire/home/me/Documents/web/my-app due to:
[$injector:nomod] Module 'fire/home/me/Documents/web/my-app' 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.
如果我在app.module.js
中移除了firebase注入,则测试为绿色我在这里做错了什么????
答案 0 :(得分:3)
你刚运气不好。
你得到一个非常奇怪的消息的原因是因为某些版本的业力中的一个错误,它在将输出打印到报告者时用{无论你的基数是}替换字符串“base”(参见issue )
因此,角度会抛出此错误:
module firebase
但业力印刷了这个:
module fireD:/Documents/web/app
这让你大吃一惊!
您收到错误的原因是因为您还需要加载angularfire:
'bower_components/firease/firebase.js',
'bower_components/angularfire/dist/angularfire.js
(而且你的 firebase 拼错了 firease )
我建议您将业力更新到最新版本(尽管该错误在某个阶段显然已经恢复)
顺便说一句,Karma通常不会很好地告诉你何时找不到文件,但是你可以用更高的日志级别运行它,它会告诉你它实际上在哪里查找文件:
karma start --log-level DEBUG
答案 1 :(得分:0)
Angular会引发错误/异常,因此请检查您的网络应用中是否引用了firebase.js
,而不仅仅是karma.conf.js
files
部分。