mercredi 3 février 2016

Unit Testing $scope.$on AngularJS

Hello Everyone I am struggling at testing a $.on function and I am looking for any suggestions or help on this:

controller

  $scope.$on("sampleFilesSelected", function(event, args) {
                $scope.sampleFiles = args.newSampleFiles;
            }); 

spec

describe('Testing a $.on', function() {
  var $scope = null;
  var ctrl = null;


  beforeEach(module('test'));

  it('should invoke myEvent when "myEvent" broadcasted', inject(function($rootScope, $controller) {
    $scope = $rootScope.$new();

    ctrl = $controller('MainCtrl', {
      $scope: $scope
    });

    $scope.$broadcast('myEvent');
    expect($scope.sampleFilesSelected).toBe(true);
  }));
});

error

TypeError: Unable to get property 'newSampleFiles' of undefined or null reference
        undefined

Aucun commentaire:

Enregistrer un commentaire