Honk! Test Net!
Some tools to help test browser-based network-y things in a headless environment.
XMLHttpRequest
The underlying mock-thing-out-er-ator is based on Philipp von Weitershausen's mock_server.js impl. Seems to work well.
In a Mocha or Jasmine environment, including this file will give you a @server properly set up and torn down around all your tests.
Usage in Mocha or Jasmine is as so:
require 'honk-test-net/lib/http_server' describe 'Remote Pants Service'-> it 'should give me info on pants' @serverwhen 'GET''/pants' status: 200 body: 'Pants Found' $get '/pants' : expectrespdatatoequal 'Pants Found' done
In another test environment that doesn't implement a beforeEach/afterEach, you can instantiate an instance like, passing your DOM window as an argument. Here's a qunit example.
jsdom = require'jsdom'jsdomglobal.document or= jsdomglobal.window or= globaldocumentcreateWindow HttpServer = require 'honk-test-net/lib/http_server' asyncTest 'Remote Pants Service'-> server = globalwindow serverwhen 'GET''/pants' status: 200 body: 'Pants Found' $get '/pants' : equalrespdata'Pants Found''Got those pants.' start