vendredi 22 avril 2016

Cannot spy on Titanium.Network methods with Jasmine

I'm using Jasmine to write tests for a Titanium project. I have a custom util js to provide me information about the network availability.

In this util there is a helper method calling Titanium.Network.getNetworkType() to retrieve the current active network type. The action I do depends on the network type retrieved by this call. To ensure test coverage on this, I'm writing Jasmine tests. But unfortunately I'm having issues with spying on Titanium.Network.getNetworkType()

Code snippet:

console.log(Titanium.Network.getNetworkType()); // returns 1

spyOn(Titanium.Network, 'getNetworkType').andReturn(666);

console.log(Titanium.Network.getNetworkType()); // returns 1

Spying on a method of Titanium (e.g. getApiName()) does work. Any ideas on this?

Thanks.

Aucun commentaire:

Enregistrer un commentaire