bardjs
bardjs copied to clipboard
Issue testing routes using bardjs
I have a similar issue to "cannot test my routes using bardjs #14'
PhantomJS 1.9.8 (Mac OS X 0.0.0) UploadController "before each" hook for "should be created successfully" FAILED Error: [$injector:unpr] Unknown provider: routerHelperProvider <- routerHelper http://errors.angularjs.org/1.4.7/$injector/unpr?p0=routerHelperProvider%20%3C-%20routerHelper
I note your comment about whether the dependencies have been included in the test harness. I am using gulp and from what i can tell all the required files have been loaded into specs.html - routerHelperProvider and routerHelper. There are other tests that rely on these being there.
The only thing i can think is that I am doing something differetly with the test for this specific module:-
Controller looks like:-
(function () { 'use strict';
angular
.module('app.upload',['angularFileUpload'])
.controller('UploadController', UploadController);
UploadController.$inject = ['logger','FileUploader','$scope'];
/* @ngInject */
function UploadController(logger, FileUploader, scope) {
var vm = this;
vm.title = 'Upload';
var uploader = scope.uploader = new FileUploader({
url: '/upload'
});
activate();
function activate() {
logger.info('Activated Upload View');
}
// FILTERS
uploader.filters.push({
name: 'customFilter',
fn: function(item /*{File|FileLikeObject}*/, options) {
return this.queue.length < 10;
}
});
// CALLBACKS
uploader.onWhenAddingFileFailed = function(item /*{File|FileLikeObject}*/, filter, options) {
console.info('onWhenAddingFileFailed', item, filter, options);
};
uploader.onAfterAddingFile = function(fileItem) {
console.info('onAfterAddingFile', fileItem);
};
uploader.onAfterAddingAll = function(addedFileItems) {
console.info('onAfterAddingAll', addedFileItems);
};
uploader.onBeforeUploadItem = function(item) {
console.info('onBeforeUploadItem', item);
};
uploader.onProgressItem = function(fileItem, progress) {
console.info('onProgressItem', fileItem, progress);
};
uploader.onProgressAll = function(progress) {
console.info('onProgressAll', progress);
};
uploader.onSuccessItem = function(fileItem, response, status, headers) {
console.info('onSuccessItem', fileItem, response, status, headers);
};
uploader.onErrorItem = function(fileItem, response, status, headers) {
console.info('onErrorItem', fileItem, response, status, headers);
};
uploader.onCancelItem = function(fileItem, response, status, headers) {
console.info('onCancelItem', fileItem, response, status, headers);
};
uploader.onCompleteItem = function(fileItem, response, status, headers) {
console.info('onCompleteItem', fileItem, response, status, headers);
};
uploader.onCompleteAll = function() {
console.info('onCompleteAll');
};
console.info('uploader', uploader);
}
})();
Spec looks like:-
/* jshint -W117, -W030 */ describe('UploadController', function() { var controller;
beforeEach(function() {
bard.appModule('app.upload');
bard.inject('$controller', '$log', '$rootScope');
});
beforeEach(function () {
controller = $controller('UploadController');
$rootScope.$apply();
});
bard.verifyNoOutstandingHttpRequests();
describe('Upload controller', function() {
it('should be created successfully', function () {
expect(controller).to.be.defined;
});
describe('after activate', function() {
it('should have title of Upload', function() {
expect(controller.title).to.equal('Upload');
});
it('should have logged "Activated"', function() {
expect($log.info.logs).to.match(/Activated/);
});
});
});
});
If i understand correctly i dont need to pass dependencies to the module being tested within the spec - as they are instantiated by the module. Only dependencies to be passed are ones used in the spec.
Appreciate any thoughts you may have.