Существует несколько опций для модульного тестирования.
Я покажу примеры с expresso & 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"
});
И пример с клятвами - это
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-это тонкая абстракция поверх клятв, с которой легче тестировать.
Однако vows-is находится в стадии активной разработки, поэтому используйте на свой страх и риск.