0

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.

3
  • 1
    Your module declaration for your app looks like it's the setter pattern as opposed to the getter. I think it should be beforeEach(module('myApp')); Commented Dec 7, 2015 at 16:30
  • That did it, thanks! Commented Dec 8, 2015 at 19:58
  • I'll add it as an answer and you can accept Commented Dec 8, 2015 at 22:01

1 Answer 1

1

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'));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.