I'm new to Node.js, express and supertest, and can't figure out how to set up a basic test. I created an app with:
express -H -c less
added mocha and supertest to the dependencies:
"dependencies": {
"mocha": "*",
"supertest": "*",
"express": "~4.2.0",
"static-favicon": "~1.0.0",
"morgan": "~1.0.0",
"cookie-parser": "~1.0.1",
"body-parser": "~1.0.0",
"debug": "~0.7.4",
"hjs": "~0.0.6",
"less-middleware": "1.0.x"
}
then wrote this simple test:
var request = require('supertest')
, express = require('express');
var app = express();
describe('Home page', function() {
it("renders successfully", function(done) {
request(app).get('/').expect(200, done);
})
}
Test fails:
1) Home page renders successfully:
Uncaught TypeError: Cannot call method 'handle' of undefined
at Function.app.handle (/Users/sarahallen/src/exp/test-first-express/node_modules/express/lib/application.js:120:16)
at Server.app (/Users/sarahallen/src/exp/test-first-express/node_modules/express/lib/express.js:28:9)
at Server.emit (events.js:98:17)
at HTTPParser.parser.onIncoming (http.js:2108:12)
at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:121:23)
at Socket.socket.ondata (http.js:1966:22)
at TCP.onread (net.js:527:27)
Software Versions:
node -v
v0.10.29
express --version
4.2.0