Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$scopeProvider <- $scope/ Unknown provider

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 to build dependency with scope in filters, services, factories, etc., but I use $scope in controller! Why am i getting this error? controller looks like

testModule.controller('TestCont', ['$filter', '$scope', function($filter, $scope){

        var doPrivateShit = function(){
            console.log(10);
        };

        this.lol = function(){
            doPrivateShit();
        };

        this.add = function(a, b){
            return a+b;
        };

        this.upper = function(a){
            return $filter('uppercase')(a);
        }   

        $scope.a = this.add(1,2);

        $scope.test = 10;

        $scope.search = {

        };
    }]);

and my test's code:

'use strict';

describe('testModule module', function(){
    beforeEach(function(){
        module('testModule');
    });

    it('should uppercase correctly', inject(function($controller){
        var testCont = $controller('TestCont');
        expect(testCont.upper('lol')).toEqual('LOL');
        expect(testCont.upper('jumpEr')).toEqual('JUMPER');
        expect(testCont.upper('123azaza')).toEqual('123AZAZA');
        expect(testCont.upper('111')).toEqual('111');
    }));
});
like image 699
Foker Avatar asked Oct 27 '14 15:10

Foker


1 Answers

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');
            ...
        });
    });
});
like image 69
Swoogan Avatar answered Oct 18 '22 23:10

Swoogan