title: Spying on a constructor using Jasmine
body: <p>I am using Jasmine to test if certain objects are created and methods are called on them.</p>
  
  <p>I have a jQuery widget that creates flipcounter objects and calls the setValue method on them.  The code for flipcounter is here: <a href="https://bitbucket.org/cnanney/apple-style-flip-counter/src/13fd00129a41/js/flipcounter.js" rel="noreferrer">https://bitbucket.org/cnanney/apple-style-flip-counter/src/13fd00129a41/js/flipcounter.js</a></p>
  
  <p>The flipcounters are created using:</p>
  
  <pre><code>var myFlipCounter = new flipCounter("counter", {inc: 23, pace: 500});
  </code></pre>
  
  <p>I want to test that the flipcounters are created and the setValue method is called on them. My problem is that how do I spy on these objects even before they are created? Do I spy on the constructor and return fake objects? Sample code would really help. Thanks for your help! :)</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I've tried spying on the flipCounter like this:</p>
  
  <pre><code>myStub = jasmine.createSpy('myStub');
  spyOn(window, 'flipCounter').andReturn(myStub);
  
  //expectation
  expect(window.flipCounter).toHaveBeenCalled();
  </code></pre>
  
  <p>Then testing for the setValue call by flipCounter:</p>
  
  <pre><code>spyOn(myStub, 'setValue');
  
  //expectation
  expect(myStub.setValue).toHaveBeenCalled();
  </code></pre>
  
  <p>the first test for initializing flipCounter is fine, but for testing the setValue call, all I'm getting is a 'setValue() method does not exist' error. Am I doing this the right way? Thanks!</p>