Reputation: 405
I have an Angularjs factory defined like:
angular.module('myapp').factory('myService', myService);
function myService($http) {
However this is not being found by my jasmine tests. If however I add an empty requires array it works in the tests but the application itself breaks.
angular.module('myapp', []).factory('myService', myService);
function myService($http) {
Looking at https://code.angularjs.org/1.5.8/docs/api/ng/function/angular.module for the requires attribute it says
If specified then new module is being created. If unspecified then the module is being retrieved for further configuration.
But I don't understand how that would break things, and how I can get both the tests and application working.
The service is included in the test file with:
describe('myService', function() {
var myService;
beforeEach(module('myapp'));
beforeEach(inject(function($injector) {
myService = $injector.get('myService');
}));
...
Upvotes: 0
Views: 38
Reputation: 405
The problem was that where my module dependencies were defined it has
angular.module('tcom.search', ['ngSanitize', 'ui.bootstrap'])
So I had to update my grunt config to include the bower components
karma: {
unit: {
options: {
frameworks: ['jasmine'],
singleRun: true,
browsers: ['PhantomJS'],
files: [
'bower_components/angular/angular.js',
'bower_components/angular-mocks/angular-mocks.js',
'bower_components/angular-sanitize/angular-sanitize.js',
'bower_components/angular-bootstrap/ui-bootstrap.js',
Upvotes: 0