01org/appframework — pull request #371 by townxelliot (2013-08-29 15:01:05+00:00)
Title: Add tests for $.ajax() and $.jsonP()

This uses a test-only HTTP server (written with Express), started during the test run, to send tailored responses for each test case.

Initially, I tried to use sinon's server and xmlhttprequest, but couldn't get these to work satisfactorily from node (the original use case was for mocking a server in the browser).

Next, I wrote a mock implementation of parts of node's http module, then attached that to a modified version of node-xmlhttprequest. However, this wasn't viable for testing $.jsonP(), where the server has to react to the content of the query in forming its response (e.g. where "?callback=json_callback22" is in the querystring, we need to return a jsonp script like "json_callback22({a: 1, b: 2});").

Coverage of the $.ajax() and $.jsonP() isn't 100% in these tests, but I wanted to get some feedback on the approach before I went any further. (NB these tests all pass.)