我正在关注phone-cat angular js示例,并尝试根据我的情况调整它以进行测试。
我的 karma.conf.js 文件:
//jshint strict: false
module.exports = function(config) {
config.set({
basePath: './app',
files: [
'https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/angular-mocks/1.6.9/angular-mocks.min.js',
'https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js',
'https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js',
'libs/jquery.fileupload.js',
'https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular-animate.min.js',
'https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular-aria.min.js',
'https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular-messages.min.js',
'https://ajax.googleapis.com/ajax/libs/angular_material/1.1.8/angular-material.min.js',
'*!(.module|.spec).js',
'**/*.spec.js',
'**/components/**'
],
autoWatch: true,
frameworks: ['jasmine'],
browsers: ['Chrome'],
plugins: [
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-jasmine'
]
});
};
这是我的文件夹/文件结构:
这是我的测试(在file-upload.component.spec.js中):
'use strict';
describe('fileupload', function() {
beforeEach(module('fileUploadApp'));
// Test the controller
describe('FileUploadController', function() {
it('test test', inject(function($componentController) {
var scope = {};
console.log("A");
var ctrl = $componentController('FileUploadController', {
$scope: scope
}); // failing on this line
console.log("B");
}));
});
});
当我尝试运行它时,我收到以下错误:
Chrome 66.0.3359(Windows 10.0.0)fileupload FileUploadController测试测试失败 错误:[$ injector:unpr] http://errors.angularjs.org/1.6.9/ $ injector / unpr?p0 = FileUploadControllerDirectiveProvider%20%3C-%20FileUploadControllerDirective 在https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js:7:76 在https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js:46:64 在Object.d [as get](https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js:43:309) 在https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js:46:126 在Object.d [as get](https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js:43:309) 在https://cdnjs.cloudflare.com/ajax/libs/angular-mocks/1.6.9/angular-mocks.min.js:1:15984 在UserContext。 (W:/AngTest/Test/app/file-upload.component.spec.js:13:18) at Object.invoke(https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js:44:390) 在UserContext.o(https://cdnjs.cloudflare.com/ajax/libs/angular-mocks/1.6.9/angular-mocks.min.js:1:20792) 错误:声明位置 在e.inject.t.mock.inject(https://cdnjs.cloudflare.com/ajax/libs/angular-mocks/1.6.9/angular-mocks.min.js:1:20326) 在套房。 (W:/AngTest/Test/app/file-upload.component.spec.js:10:21) 在套房。 (W:/AngTest/Test/app/file-upload.component.spec.js:8:3) 在W:/AngTest/Test/app/file-upload.component.spec.js:3:1 Chrome 66.0.3359(Windows 10.0.0):执行1 of 1(1 FAILED)错误(0.085秒/ 0秒)
答案 0 :(得分:0)
应为$componentController('fileUpload', ...
至少我猜fileUpload
是您的组件名称