vendredi 26 août 2016

Testing posting form in iframe to 3rd party domain

I have a JavaScript application that renders a modal with an iframe inside it. The iframe contains a form to the 3rd party. The JS app submits the form to a 3rd party who will eventually render an html page with a parent.postMessage() call within the iframe to send data back to the JavaScript application. The application works great, but now I need to write some tests for the postMessage() handler. And thats where I'm stuck.

I'm using karma, sinon.js, and mocha as my testing tools. I've had great success using sinon.js for mocking out XHR requests that the JS App is making. Unfortunately the form post isn't sent via XHR so sinon.js isn't able to intercept the request.

Is there anyway to test this in the same style I'm testing the XHR requests? Meaning somehow intercept the post request and mock the response from the 3rd party to force different scenarios in my postMessage() handler.

I could of course build a web server that the form is posted to that renders a postMessage() call, but adding an additional server adds a lot of complexity to testing and if possible I'd like to avoid that.

Aucun commentaire:

Enregistrer un commentaire