mocking for Titanium
mockti is a mocking framework for Titanium. It loads up a
of the Titanium API and creates a
Titanium object with all of the proper
objects and methods for testing code. Every proxy is an emitter (as in Ti
itself). Methods also emit an event
function::name when invoked.
Alternatively, one could use some test runner with this. This is the PhantomJS style approach.
Install it like this
$ npm i mockti
Then, use it like this
var mockti = require'mockti';// make it globalTi = mockti;var xhr = TitaniumNetworkcreateHTTPClient;var view = TiUIcreateView;
mockti() function takes as an argument the path to an
These are included with every sdk build. If you don't pass a path, it'll use
api.jsca, which currently is from 3.1.0 GA.
You'll probably want to require() some of the code in your
Currently I have my project setup with a
test folder which has a couple tests;
these require code out of Resources after requiring
mockti. Then, I attempt
requests, make assertions, etc.
You can also make http requests, which will go through the npm
Check out nock if you'd like to mock these
Simple types are asserted. For example, functions that accept a number or string will have their argument's type asserted.