Reputation: 23615
I'm trying to setup my Angular unit test in Visual Studio with Chutpah and Jasmine.
I get this error, and I'm not sure why:
This is the code to test in my timelineservice.js file (in my angular project, simplified for my first-test )
angular.module('myApp').factory('timelineService',
[
function timelineServiceInit(){
return {
exciteText: function (msg) {
return msg + '!!!';
}
};
}
]
);
This is my unit test:
describe('basicService tests', function () {
var myservicenaam;
// excuted before each "it" is run.
beforeEach(function () {
angular.mock.module('myApp', []);
var $injector = angular.injector(['myApp']);
var myService = $injector.get('timelineService');
myservicenaam = myService;
});
//it's removed
});
What is weird (imho) is that when I debug, the code goes to the 'timelineservice.js'
file first, and then the module is not loaded (which is correct).
I thought the testcode would run first and at that point load the module.
In my testproject I have references to the angular files and the code files.
When I put the angular.module('myApp', []);
code in the timelineservice.js
file, it all works.
Upvotes: 0
Views: 798
Reputation: 8959
The problem lies in the fact that you are using a setter pattern instead of a getter pattern so your app doesn't properly load. Try the following declaration before your tests:
beforeEach(module('myApp'));
Upvotes: 1