Write a Jasmine test for a simple AngularJS controller

describe('MyController', function() {
var $controller;
      beforeEach(module('myApp'));

      beforeEach(inject(function(_$controller_){
          $controller = _$controller_;
      }));

      describe('$scope.sum', function() {
          it('adds two numbers', function() {
              var $scope = {};
              var controller = $controller('MyController', { $scope: $scope });
              $scope.num1 = 2;
              $scope.num2 = 3;
              $scope.sum();
              expect($scope.result).toBe(5);
          });
      });
  });
  

 

Post your Answer