title: Mock out angular.element in Jasmine tests
body: <p>I have a function in a controller that has a call</p>
  
  <pre><code>var someVar = angular.element(event.target).scope().field;
  </code></pre>
  
  <p>I am trying to mock it by doing</p>
  
  <pre><code>var ngElementFake = function(el) {
                  return {
                      scope: function() {
                          return {
                              toggleChildElement: true,
                              field: scope.field
                          }
                      }
                  }
              }
  
  spyOn(angular, 'element').andCallFake(ngElementFake);
  </code></pre>
  
  <p>However when I call the function in the test I get the response:</p>
  
  <pre><code>TypeError: 'undefined' is not a function (evaluating 'injector.get('$rootElement').off()')
  at ../angular-mocks/angular-mocks.js:1819
  </code></pre>
  
  <p>What am I doing wrong?</p>
  
  <p>EDIT: Injection</p>
  
  <pre><code>    beforeEach(function() {
          inject(function($rootScope, $controller) {
  
              scope = $rootScope;
  
              scope.record = recordData;
  
              scope.model = 'Hierarchy';
  
              ctrl = $controller("fngHierarchyChildCtrl", {
                  $scope: scope
              });
          });
      });
  </code></pre>