I use Jasmine to check if certain objects are created and a method is called on them.
I have a jQuery widget that creates flipcounter objects and calls the setValue method on them. The code for flipcounter is here: https://bitbucket.org/cnanney/apple-style-flip-counter/src/13fd00129a41/js/flipcounter.js
Flip counters are created using:
var myFlipCounter = new flipCounter("counter", {inc: 23, pace: 500});
I want to check that flipcounters are created and the setValue method is called on them. My problem is how can I keep track of these objects even before they are created? Am I spying on the constructor and returning fake objects? Sample code really helps. Thanks for your help!:)
Update:
I tried following flipCounter as follows:
myStub = jasmine.createSpy('myStub'); spyOn(window, 'flipCounter').andReturn(myStub); //expectation expect(window.flipCounter).toHaveBeenCalled();
Then testing to call setValue using flipCounter:
spyOn(myStub, 'setValue');
The first test to initialize flipCounter is fine, but to test the setValue call, all I get is the 'setValue () method does not exist'. Am I doing it right? Thank!
javascript jasmine spy
gerky Feb 19 2018-12-12T00: 00Z
source share