title: How do I create a helper for Jasmine/Angular to combine multiple beforeEach's
body: <p>I keep repeating some code in my spec file that injects a template and then compiles it.  I extracted this code into a helper function to keep things DRY.  I believe the problem is in trying to place to <code>beforeEach</code>'s in a helper function.  Here is the piece of my code that I am trying to abstract into a function:</p>
  
  <pre><code>  beforeEach(module('app/views/header.html'));
  
    beforeEach(inject(function($templateCache, $compile, $rootScope) {
      template = $templateCache.get('app/views/header.html');
      $templateCache.put('views/header.html', template);
      var directive = angular.element('&lt;clinical-header&gt;&lt;/clinical-header&gt;');
      element = $compile(directive)($rootScope);
      $rootScope.$digest();
    }));
  </code></pre>
  
  <p>Here is the helper function that I created: </p>
  
  <pre><code>var setupTemplate = function(templateName, element) {
    beforeEach(module('app/views/' + templateName));
    beforeEach(inject(function($templateCache, $compile, $rootScope) {
      var template = $templateCache.get('app/views/' + templateName);
      $templateCache.put('views/' + templateName, template);
      var directive = angular.element(element);
      element = $compile(directive)($rootScope);
      $rootScope.$digest();
    }));
  </code></pre>
  
  <p>And now this is the call to the helper function:</p>
  
  <pre><code>setupTemplate('header.html', '&lt;clinical-header&gt;&lt;/clinical-header&gt;');
  </code></pre>
  
  <p>At the end of my helper function, everything looks good, but when I jump to my <code>it</code> block, everything is undefined.  Can I extract multiple <code>beforeEach</code>'s?  What is the right way to do this?  Also, where is the proper place to put jasmine helper functions and how is that done?</p>