0
我是新來的測試驅動開發,並試圖使用supertest來教我自己。我很困惑,爲什麼我不斷收到錯誤「應用程序未定義」?從我的電話請求(應用程序),我在下面加了粗體。我試圖查看文檔,但似乎沒有太多。我所有的線路都處於所謂的「中間件」的文件,該文件開頭是這樣的:SuperTest - 應用程序未定義
var bodyParser = require('body-parser');
var helpers = require('./helpers.js'); // our custom middleware
var db = require('../DB/DB.js');
var router = require('../routes.js');
var path = require('path');
var fs = require('fs');
var gm = require('gm');
module.exports = function (app, express) {}
,我用supertest測試中間件文件的路徑的實際文件:
var chai = require('chai')
var assert = chai.assert;
var should = chai.should();
var expect = chai.expect;
var helpers = require("../config/helpers.js");
var middleware = require("../config/middleware.js");
// for when we eventually want to test against mock data
var fs = require('fs');
var path = require('path');
var supertest = require("supertest")(middleware);
describe('middleware API', function() {
it('responds with binary data', function(done) {
var imagePath = path.join(__dirname, '/../assets/drawings/', userName + '.png');
**request(app)**
.get(imagePath)
.expect(201)
.expect('Content-Type', 'image.png')
.parse(binaryParser)
.end(function(err, res) {
if (err) return done(err);
// binary response data is in res.body as a buffer
assert.ok(Buffer.isBuffer(res.body));
console.log("res=", res.body);
done();
});
});
it('sends back one image', function(done) {
**request(app)**
.get('/game/')
.expect(201)
.expect('Content-Type', 'image.png')
.expect('Content-Length', '1')
.parse(binaryParser)
.end(function(err, res) {
if (err) return done(err);
// binary response data is in res.body as a buffer
assert.ok(Buffer.isBuffer(res.body));
console.log("res=", res.body);
done();
})
})
})