dimanche 4 octobre 2015

Angular testing with Jasmine global variable populate

I am trying to create test cases based on Jasmin framework for Angular code. There is a global variable which is being used in my angular controller, so while creating my Jasmine test spec, I want to prepopulate the global variable before i initialize the angular controller.

How can I do that?

Jasmine code -

describe("personCtrl", function() {
    var $rootScope, $scope, controller;

    beforeEach(function() {
        module('myApp');

        inject(function($injector){
            $rootScope = $injector.get('$rootScope');
            $scope = $rootScope.$new();
            controller = $injector.get('$controller')("personCtrl", {$scope : $scope});
            controller.cantactListJS = '';
        });
    });

    describe("Initialization", function() {
        it("should initialize values correctly", function() {
            expect(true).toBeTruthy();
        });
    });
});

Here "cantactListJS" is a global variable wwhich I want to populate first before my test executes.

Angular code if relevant can be found here - http://ift.tt/1M8VgNw

Thanks, Ray

Aucun commentaire:

Enregistrer un commentaire