0
votes

I'm trying to adapt this answer to my creation and testing of a factory..

Failing unit test of factory with dependency in AngularJS using Jasmine & Karma

Anyhow, I'm getting this error..

Error: [$injector:unpr] Unknown provider: ModulizerFactoryProvider <- ModulizerFactory

Here's my code, fairly blank, but should pass.

angular.module( 'modulizer', [
'ui.router',
'ui.bootstrap'
])
.factory('ModulizerFactory', function() {
        function Modulizer(modules) {
            this.modules = modules;
        }
        return Modulizer;
    })

Here's my test:

describe( 'Modulizer', function() {
    describe( 'make_apiUrlFn', function() {
        var AppCtrl, $location, $scope;

        beforeEach(module( 'modulizer' ) );
        beforeEach( inject( function( $injector ) {
            myFactory = $injector.get('ModulizerFactory');
        }));
        it( 'should exist', inject( function(myFactory) {
            expect(myFactory).toBeDefined();
        }));
    });
});
1
Silly question perhaps, but are you loading the code in Karma? The test code looks okay to me.Ed_
Are you asking whether I'm using Karma (yes), or I should check for an error in my karma.conf.js file (I've got a *.js line in files: that should be picking up the file, and it is, as it's logging some console.log lines that are in the file)Jon Thompson

1 Answers

0
votes

So there were two things going on..

First, something was wonky with my grunt watch process, which was making none of my changes in the source file get applied.

Second, there is a bug in the test posted above...

describe( 'Modulizer', function() {
    describe( 'make_apiUrlFn', function() {
        var AppCtrl, $location, $scope;

        beforeEach(module( 'modulizer' ) );
        beforeEach( inject( function( $injector ) {
            myFactory = $injector.get('ModulizerFactory');
        }));
        it( 'should exist', inject( function(ModulizerFactory) {
            expect(myFactory).toBeDefined();
        }));
    });
});

The difference is in the 'should exist' line.