【发布时间】:2017-08-19 00:24:36
【问题描述】:
我目前正忙于对 Angular 进行 jasmine 单元测试。 我已将此单元测试放在 test.js 中
describe('The countInput filter', function(){
var $filter;
beforeEach(function(){
module('countInputFilter');
inject(function(_$filter_){
$filter = _$filter_;
});
});
it('Should not give an output when the length of the input is > 3', function(){
var input = 'test';
result = $filter('countInputFilter')(input);
expect(result).toBe(null);
});
});
当我使用 karma start karma.conf.js 运行它时,我收到错误:未定义模块。
在我的 karma.conf.js 文件中,我有以下文件代码:
files: [
'../bower_components/angular/angular.js',
'../bower_components/angular-mocks.js',
'../bower_components/angular-route/angular-route.js',
'../scripts/**/*.js',
'../scripts/filters.js',
'spec/**/*.js',
'spec/*.js'
],
而我的项目结构是:
scripts
--filters.js
test
--spec
----test.js
--karma.conf.js
第一次尝试使用 Jasmine 进行单元测试,但我没有看到错误。
26 03 2017 11:29:10.103:WARN [watcher]:模式“C:/Users/user/Desktop/angular/bower_components/angular-mocks.js”不匹配任何文件。 26 03 2017 11:29:10.134:WARN [业力]:没有捕获的浏览器,打开 http://localhost:9876/ 26 03 2017 11:29:10.150:INFO [karma]: Karma v1.5.0 服务器开始于http://0.0.0.0:9876/ 2017 年 2 月 3 日 11:29:10.150:INFO [启动器]:以无限并发启动浏览器 Chrome 26 03 2017 11:29:10.181:INFO [启动器]: 启动浏览器 Chrome
【问题讨论】: