samedi 5 septembre 2015

how do i unite test method in directive with spyOn?

i am trying to unit test buildchart method which is in my directive with spyOn in specs but it gets failed and give me this error:

 ReferenceError: Can't find variable: buildChart

here is my directive code where i define it:

    $scope.build = function buildChart(selector, data, chosenColor) {//some code}

in specfile:

  it('should ', function () {
        var buildSpy = spyOn($scope, '$scope.build');
         $scope.$broadcast('#chart1', '$scope.data', '$scope.fileSummaryColor');
        $scope.digest();
        expect(buildSpy).toHaveBeenCalled();

      });

how can i test this?

Aucun commentaire:

Enregistrer un commentaire