I'm new to TDD and I am trying to write testable code which uses a third party libraries (cross platform mobile development). I would like to have tests to only to check our business logic. Not to worry about their implementation.
More over their libraries are exposed only in native wrappers. Since use js as development language I would like to test using jasmine and run test to check my business logic only in browser.
Here are the patterns of methods I would like to ignore/mock when testing.
com.companyname.net.checkInternetAvailable(url)
com.companyname.store.getValue(key)
com.companyname.someother.name(whateverObj, callback) etc.,
At the moment, I have created a new mocks.js file where I simply wrote
var com = {
"net":{},
"store":{},
"someother":{}
}
com.net.checkInternetAvailable = function(url){
//TODO: fix this!
return true;
}
and I do the same for all the methods in my code. I tried to use Jasmine SpyOn(com.net, "checkInternetAvailable").and.returnValue(true) instead of defining all the methods. Problem with this approach is I had to define all the methods to use SpyOn.
Is there a simpler way to do this? What is the recommended approach?