nodeunit-express
nodeunit-express is a utility function to make it easy to write tests for Node.JS Express applications. It is based on the https://github.com/rubymaverick/express-mock-request project, which I could not get to work properly.
How to use:
First, install using npm:
npm install nodeunit-express
Then require it in your test file like so:
var request = ;
Let's say you want to test this simple express app to make sure it returns the proper status, body, and headers:
var express = var app = moduleexports = ; app; // Only start listening on 8080 when this file is run directly i.e.: node app.jsif!moduleparent app;
You could write your test like so:
var request = ;// require the express application, notice how we exported the express app using `module.exports` abovevar app = ; // This is a nodeunit test exampleexports{ var express = ; express;}
Tester
var testerInitializer = ;var app = ; var globalOptions = { if resbody != null resbody = JSON; return res; }; var tester = ; moduleexports'test test' = ;