-
Notifications
You must be signed in to change notification settings - Fork 307
Using Intern to unit test Ajax calls
Colin Snover edited this page Aug 2, 2013
·
9 revisions
When writing unit tests with Intern, occasionally you will need to interact with a Web service using XMLHttpRequest. However, because the test runner serves code localhost:9000
by default, any cross-origin requests will fail. In order to test Ajax requests without using CORS or JSONP, the solution is to set up a reverse proxy to Intern and tell the test runner to load from that URL instead. You can either set up the Web server to only send requests to Intern for your JavaScript files, or you can set up the Web server to send all requests to Intern except for the Web services you’re trying to access.
- Modify the
proxyUrl
in your Intern configuration to point to the URL where the Web server lives - Set up the Web server to reverse proxy to
http://localhost:9000/
by default - Add location directives to pass the more specific Web service URLs to the Web service instead
- Modify the
proxyUrl
in your Intern configuration to point to the URL where the Web server lives - Set up the Web server to reverse proxy to
http://localhost:9000/
for the special/__intern
location, plus any directories that contain JavaScript
Reverse proxy configuration information for common Web servers: