【发布时间】:2013-12-16 22:04:00
【问题描述】:
我一直在学习 AngularJS,现在是时候开始编写测试了,但我遇到了第一个障碍。
我的业力配置文件是:
module.exports = function(config) {
config.set({
basePath: '..',
// frameworks to use
frameworks: ['mocha'],
// list of files / patterns to load in the browser
files: [
'node_modules/chai/chai.js',
'public/js/libs/jquery-1.9.1.js',
'public/js/libs/angular.js',
'test/libs/angular-mocks.js',
'public/js/**/*.js',
'test/angular/**/*.js'
],
exclude: [],
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_DEBUG,
autoWatch: true,
browsers: ['Chrome'],
captureTimeout: 60000,
singleRun: false
});
};
我声明了一个过滤器:
angular.module('timeMachine.filters',[])
.filter('hours', function() {
return function(input) {
return input == 1
? '1 hour'
: input + ' hours';
}
});
还有一个测试:
var should = chai.should();
describe("The hours filter", function() {
beforeEach(function() {
angular.module('timeMachine.filters');
});
it('should be able to test', function(){
true.should.equal(true);
});
it('should be able to inject an hours filter', inject(function($filter) {
var hours = $filter('hours');
expect(hours).not.to.equal(null);
}));
});
但是,第二次测试失败并显示以下消息:
[$injector:unpr] 未知提供者:hoursFilterProvider
在运行的 Angular 应用程序的上下文中,此过滤器有效。
我认为由于缺乏经验而遗漏了一些东西,任何帮助都会很棒!
【问题讨论】:
-
我还不太擅长测试,但是 egghead.io 有很多关于这方面的教程可能会有所帮助。
标签: angularjs karma-runner angularjs-filter