title: How to spyOn a global function and return a value in Jasmine
body: <p>How can I spy on <code>MyFunction</code> and return <code>2</code> in Jasmine 2.0?</p>
  
  <p>I have the following code that errors on the first line inside <code>shouldPass</code> with:</p>
  
  <blockquote>
    <p><code>Error: function MyFunction(){ return 1; }() method does not exist</code> </p>
  </blockquote>
  
  <p>It appears to be using the entire function as the function name</p>
  
  <p>MyFile.js:</p>
  
  <pre><code>MyFunctionToTest = function(){
      return MyFunction() + 1;
  }
  
  function MyFunction(){ return 1; }
  </code></pre>
  
  <p>MyFileSpec.js:</p>
  
  <pre><code>describe("myTest", function(){
      it("shouldPass", function(){
          spyOn("MyFile", MyFunction).and.returnValue(2);
  
          expect(MyFunctionToTest()).toEqual(3)
      })
  })
  </code></pre>