一旦完成調用被調用,我的摩卡測試似乎並沒有停止。我有點難過,因爲它看起來幾乎和我在網上找到的所有東西一樣。摩卡測試超時
這是test.js文件的完整部分。
var request = require('supertest');
var app = require('../app.js');
describe('GET /', function() {
it('Should be status code 200', function(done) {
request(app).get('/').expect(200, done);
});
});
,這是我的app.js
// set variables for environment
var express = require('express');
var app = express();
var path = require('path');
// Set port
app.set('port', (process.env.PORT || 4000));
// Views as directory for all template files
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade'); // use either jade or ejs
// Instruct express to server up static assets
app.use(express.static('public'));
// Set routes
app.get('/', function(req, res) {
res.render('index');
});
// Main
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});
module.exports = app;
我得到這個輸出
Node app is running on port 4000 GET/ âœ「 Should be status code 200 (141ms)
1) "after all" hook for "Should be status code 200"
1 passing (2s) 1 failing
1) "after all" hook for "Should be status code 200": Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test
。
你從app.js導出了什麼? – beautifulcoder