jeudi 25 juin 2015

Can't get this unit test (on a helper) to run without exceptions - AngularJS, Karma, Jasmine

I'm new to Angular and Karma and every site out there seems to recommend a different way of writing unit tests, which makes all of this very confusing. Help is appreciated!

I have a helper class that has a dependency on a service class. I am writing a unit test for the helper class. I have this:

module("myModule");

    it('works!', inject(function(myHelper) {

        module(function($provide) {
            $provide.service('myService', function() {
                payload = spyOn(myService, 'getPayload').andReturn(
                    {id: 1 });
                });
        });


        expect(myHelper.getSomeData()).toEqual(exepectedData);
    }));

The exception I'm getting when running the test is:

Error: [$injector:unpr] Unknown provider: myHelperProvider <- myHelper

I've tried all different ways of doing this, but haven't gotten it to work yet.

Aucun commentaire:

Enregistrer un commentaire