I'm using the superagent ajax library for an app, and I'm trying to write some unit tests for it. I've got a class which looks like this:
someClass = {
getData: function(){
_this = this;
superagent.get('/some_url').end(function(res){
if(res.body){
_this.data = res.body
}
});
});
}
How do I write a Jasmine test to spy on the _this.data = res.body
call? Setting up a spy with and.callThrough()
on getData
isn't working. I don't want to actually call the URL in question; I'm just trying to test that if it gets data, it does something with it.
Thanks
spyOn(superagent, 'get').and.callFake(function(url) {
return {
end: function(cb) {
//null for no error, and object to mirror how a response would look.
cb(null, {body: data});
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With