lundi 27 juillet 2015

How to test rootscope in my angular app

I am having an issue on testing the rootscope in my case

I have something like

describe('test controller', function () {
    var myCtrl, scope, rootScope;

    beforeEach(module('myApp'));
    beforeEach(inject(function (_$controller_, _$httpBackend_, _$rootScope_, _Course_) {
        rootScope   = _$rootScope_;
        scope        = _$rootScope_.$new();

        rootScope = {item:{condition:'new'}};

        myCtrl = _$controller_('myCtrl', {
            $scope: scope
        });
    }));

    describe('test', function() {
        it('should test rootscope' , function() {
            scope.setCondition('old');
        });
    });
});

html

   $scope.setCondition = function(con) {
            $scope.condition  = con;
            setRoot(con);
    };

    var setRoot = function(con) {
        $rootScope.item.condition = con;
    }

I am getting 'undefined' is not an object (evaluating '$rootScope.item.condition=con')

I am not sure what went wrong as I specify my rootscope inside beforeEach. Can anyone help me about it? Thanks a lot!

Aucun commentaire:

Enregistrer un commentaire