uploadCtrl.js
'use strict';
angular.module('app.controllers').controller('UploadCtrl', ['$scope', 'FileUploader',
function ($scope, FileUploader) {
$scope.uploader = new FileUploader();
$scope.upload = function () {
// Do some validation of form fields before submitting to server here...
$scope.success = true;
};
}]
);
uploadCtrlSpec.js
'use strict';
describe('UploadCtrl', function () {
var scope, controller, FileUploader, UploadCtrl;
beforeEach(module('app.controllers'));
beforeEach(module('angularFileUpload'));
beforeEach(inject(function (_FileUploader_, $rootScope, $controller) {
scope = $rootScope.$new();
FileUploader = _FileUploader_;
controller = $controller;
UploadCtrl = controller('UploadCtrl', {$scope: scope, FileUploader: FileUploader});
}));
it('verify upload success', function () {
scope.upload();
expect(scope.success).toBeTruthy();
});
});
When I try to run this test I get:
Error: [$injector:unpr] Unknown provider: FileUploaderProvider <- FileUploader
I have tried to remove all down to very the very basic to rule out other issues. If I change the "FileUploader" variable to FileUploaderX" I get the same error and only the unknown provider name changes, so the problem seem to be within the unit test injection. Also if I change the "beforeEach(module('angularFileUpload'));" to for example "beforeEach(module('angularFileUploadX'));" I get an error that the module could not be found, so the test conf seem to be including the script for the module correctly.
The application works and I'm able to upload a file to my server (not visible here since I removed all logic except for the FileUploader initiation to rule out other issues).
Anyone got any ideas?
Btw, I'm using this module: nervgh/angular-file-upload
Aucun commentaire:
Enregistrer un commentaire