I have a question about using a spy in the following situation.
Let's say I'm testing function myClass.blah. Within that method, I'm instantiating ha of type Ha. I'd like to spy on ha.hoo method to make sure it was called.
MyClass.prototype.blah() = function { this.ha = new Ha(); this.ha.hoo(); };
Below is an obviously incorrect way of doing this, but illustrates what I'd like to do. What would be the correct way to it?
it('setupDetection', function () { var myClass = new MyClass();
spyOn(myClass.ha 'hoo'); //This understandably won't work as myClass.ha does not exist yet. How do I spy on it?
myClass.blah();
expect(myClass.ha.hoo).toHaveBeenCalled(); });
I'm fairly new to Jasmine. Any help would be much appreciated.
Thanks, JC
it('setupDetection', function(){ var myClass = new MyClass(),
ha = new Ha(),
haFactory = function() { return ha; };
spyOn(ha, "hoo");
myClass.blah(haFactory);
expect(ha.hoo).toHaveBeenCalled();
});
--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jasmine-js+...@googlegroups.com.
To post to this group, send email to jasmi...@googlegroups.com.
Visit this group at http://groups.google.com/group/jasmine-js.
For more options, visit https://groups.google.com/groups/opt_out.