There are several options for module testing modules.
I will show examples with expressions and vows.
var assert = require('assert'), http = require('http'), server = getServer(); // get an instance of the HTTPServer assert.response(server, { 'url': '/' }, { 'body': "test body", 'status': "200" });
And the example with vows-is
var is = require("vows-is"); is.config({ server: { "factory": createServer, "kill": destroyServer, "uri": "http://localhost:4000" } }) is.suite("integration tests").batch() .context("a request to GET /") .topic.is.a.request("GET /") .vow.it.should.have.status(200) .vow.it.should.have .header("content-type", "text/html; charset=utf-8") .context("contains a body that") .topic.is.property('body') .vow.it.should.be.ok .vow.it.should.include.string("hello world") .suite().run({ reporter: is.reporter }, function() { is.end() });
vows-is is a subtle abstraction on top of a vow to make testing easier.
However, vows are under active development, so use at your own risk.
source share