ノードアプリ用の RESTful API を構築しようとしています。ルートを構築しましたが、すべて正常に動作しています。しかし、テストしようとすると、テスト中ではなく正常に機能しているにもかかわらず、DELETE メソッドを機能させることができません。
サーバーとテストのコードは次のとおりです。サーバ:
// set up
var express = require('express');
var app = express(); // create our app w/ express
var path = __dirname; //root path
// configuration
app.configure(function() {
app.use(express.static(path));
//app.use(express.logger('dev')); // log every request to the console
app.use(express.json());
app.use(express.urlencoded()); // pull information from html in POST
app.use(express.methodOverride()); // simulate DELETE and PUT
});
function start() {
// routes
require('./app/routes.js')(app);
// listen (start app with node server.js)
app.listen(process.env.PORT || 5000);
console.log("Server listening for incoming conections..");
}
//************************
exports.start = start;
exports.server = app;
テスト:
var should = require('should');
var assert = require('assert');
var request = require('supertest');
var mongoose = require('mongoose');
var express = require('express');
var server = require(__dirname + './../index.js');
describe('Routing', function() {
var url = 'http://localhost:5000';
it('should return status 200 after DELETING a bus', function(done) {
request(url)
.delete('/api/buses/' + bus.id)
.end(function(err, res) {
if (err) {
throw err;
}
res.should.have.status(200);
done();
});
});
});
そして、これはそれがスローするエラーメッセージです:
Routing
1) should return status 200 after DELETING a bus
✖ 1 of 1 test failed:
1) Routing should return status 200 after DELETING a bus:
TypeError: Object #<Object> has no method 'delete'
at Context.<anonymous> (/home/roger/Documents/Buse/test/test.js:63:16)
at Test.Runnable.run (/home/roger/Documents/Buse/node_modules/mocha/lib/runnable.js:196:15)
at Runner.runTest (/home/roger/Documents/Buse/node_modules/mocha/lib/runner.js:351:10)
at /home/roger/Documents/Buse/node_modules/mocha/lib/runner.js:397:12
at next (/home/roger/Documents/Buse/node_modules/mocha/lib/runner.js:277:14)
at /home/roger/Documents/Buse/node_modules/mocha/lib/runner.js:286:7
at next (/home/roger/Documents/Buse/node_modules/mocha/lib/runner.js:234:23)
at Object._onImmediate (/home/roger/Documents/Buse/node_modules/mocha/lib/runner.js:254:5)
at processImmediate [as _immediateCallback] (timers.js:330:15)
make: *** [test] Error 1