Getting Unknown Provider error when injecting a Service into an Angular unit test

后端 未结 4 1622
难免孤独
难免孤独 2021-02-06 23:01

I\'m fairly new to Angular and have reviewed all the similarly related questions on Stack Overflow but none have helped me. I believe I have everything set up correctly but am s

4条回答
  •  死守一世寂寞
    2021-02-06 23:33

    Have you tried defining an additional module that depends on your other aggregated modules like so:

    angular.module( 'dashboard', [ 'dashboard.services', 'dashboard.controllers' ] )
    

    So you can in the beforeEach specify the one module that has both submodules defined in it like so:

    describe('Browse Controller Tests.', function () {
        beforeEach(function () {
            module('dashboard');
        });
    
        var controller, scope, eventingService;
    
        beforeEach(inject(function ($controller, $rootScope, EventingService) {
            scope = $rootScope.$new();
            eventingService = EventingService
    
            controller = $controller('Browse', {
                $scope: scope,
                eventing: eventingService
            });
        }));
    
    
        it('Expect True to be True', function () {
            expect(true).toBe(true);
        });
    });
    

提交回复
热议问题