vendredi 16 septembre 2016

What is the easiest way to listen for and verify an AJAX call in a test environment?

We have a JavaScript snippet that is installed on a cilent's page (think analytics/event tracking). We want to run this snippet's tests on as many browsers as possible (ie. Browserstack or similar). One thing we explicitly want to test is the JSON POST that it does with the event data. Right now, we're stubbing out the XMLHttpRequest calls and just verifying that they're called, but for completeness purposes we'd like to actually run the AJAX calls through the real browser stack, just in case some browsers do funky stuff we don't expect (like XDomainRequest in older IE).

Right now, all the tests are written in pure JavaScript that runs in the browser. If we stop stubbing the AJAX calls and actually send them through the browser, we will need to have some server listening to catch the calls and somehow communicate success or failure to the test library.

I could set up a simple server (probably NodeJS/Express) that has a single route for the AJAX call, but before I do that, I thought I'd ask if someone else has a better idea. Is there a tool specifically for this? Is there a way to avoid the server-side component completely, while still allowing the browser to actually POST the data somewhere?

Basically, I just want something that receives the POST and signals success of the test, and I want to write as little code as possible.

Aucun commentaire:

Enregistrer un commentaire