I've just switched over to using ui-router. I've got a simple navbar directive that calls a templateURL but in Karma unit testing it's causing an exception
Error: Unexpected request: GET /directives/nav-bar/nav-bar.html No more request expected
navbar directive:
'use strict';
angular.module('kitchenapp')
.directive('navBar', function () {
return {
restrict: 'E',
templateUrl: '/directives/nav-bar/nav-bar.html'
};
});
navbar spec:
'use strict';
describe('Directive: nav-bar', function () {
beforeEach(module('kitchenapp', 'templates'));
var element, scope;
beforeEach(inject(function ($compile, $rootScope, $httpBackend) {
scope = $rootScope.$new();
element = angular.element('<nav-bar></nav-bar>');
element = $compile(element)(scope);
scope.$apply();
//$httpBackend.expectGET("/directives/nav-bar/nav-bar.html");
$urlRouterProvider.otherwise(function(){return false;});
}));
it('\'s brand link should be titled \'KitchenApp\' and should navigate to the root address when clicked', function () {
console.log('Element', element);
});
});
As you can see in the spec, I've tried lots of methods in the beforeEach and it never seems to make a difference.
Any help greatly appreciated.
EDIT Karma.conf.js
'use strict';
module.exports = function (config) {
config.set({
basePath: 'client',
frameworks: ['jasmine'],
preprocessors: {
'**/*.html': ['ng-html2js']
},
ngHtml2JsPreprocessor: {
stripPrefix: 'client/',
moduleName: 'templates'
},
plugins: [
'karma-phantomjs-launcher',
'karma-jasmine',
'karma-ng-html2js-preprocessor'
],
files: [
'bower_components/angular/angular.js',
'bower_components/angular-ui-router/release/angular-ui-router.js',
'bower_components/angular-mocks/angular-mocks.js',
'bower_components/angular-bootstrap/ui-bootstrap-tpls.js',
'bower_components/angular-ui-grid/ui-grid.js',
'bower_components/angular-ui-calendar/src/calendar.js',
'bower_components/angular-animate/angular-animate.js',
'bower_components/angular-sanitize/angular-sanitize.js',
'bower_components/angular-cookies/angular-cookies.js',
'bower_components/angular-resource/angular-resource.js',
'bower_components/angular-socket-io/socket.min.js',
'app.js',
'views/**/*.js',
'services/**/*.js',
'directives/**/*.js',
'directives/**/*.html',
'filters/**/*.js'
],
exclude: [
'views/**/*.e2e.js',
'services/socket/socket.service.js'
],
reporters: ['progress'],
port: 9876,
colors: true,
// possible values:
// config.LOG_DISABLE
// config.LOG_ERROR
// config.LOG_WARN
// config.LOG_INFO
// config.LOG_DEBUG
logLevel: config.LOG_INFO,
autoWatch: false,
browsers: ['PhantomJS'],
singleRun: true
});
};