$scopeProvider <- $scope/ Unknown provider

后端 未结 3 567
执笔经年
执笔经年 2021-02-05 10:02

I testing my angular-application with jasmine(http://jasmine.github.io/2.0/) and getting next error: Unknown provider: $scopeProvider <- $scope I know, that it\'s incorrect

3条回答
  •  温柔的废话
    2021-02-05 10:31

    You need to manually pass in a $scope to your controller:

    describe('testModule module', function() {
        beforeEach(module('testModule'));
    
        describe('test controller', function() {
            var scope, testCont;
    
            beforeEach(inject(function($rootScope, $controller) {
                scope = $rootScope.$new();
                testCont = $controller('TestCont', {$scope: scope});
            }));
    
            it('should uppercase correctly', function() {
                expect(testCont.upper('lol')).toEqual('LOL');
                expect(testCont.upper('jumpEr')).toEqual('JUMPER');
                ...
            });
        });
    });
    

提交回复
热议问题