Node.js / Mocha / Supertest REST api – 一个del()停止工作后,我添加了第二套房

所以我有一个模型,我试图testing。 它具有自定义终结点以及标准REST终结点。 我build立了一个套件来testing标准操作。 首先,我张贴了,然后我插入(一个没有身份证…基本上是一个职位),然后我得到了。 最后,我删除了我发布时创build的条目,并且在我自己之后进行清理,以便删除我已插入的点。 这工作,这是很好的。

然后,在同一个文件中,我添加了另一个套件,这个套件testing我的自定义端点。 现在我的钩子应该删除插入点失败。 这不好。 我尝试在新的描述语句中包装我的testing删除,但它再次没有工作。 最后,我完全抛弃了这个钩子,只是发了两个.del的电话,但它仍然不起作用。 我在我的智慧结束。 请让我知道,如果你能弄清楚为什么这不起作用,以及如何使其工作。 先谢谢你!

这是我的代码:

var request = require('supertest'); var app = require('../server'); var chai = require('chai'); var chance = require('chance').Chance(); var assert= require('assert'); function json(verb, url) { return request(app)[verb](url) .set('Content-Type', 'application/json') .set('Accept', 'application/json') .expect('Content-Type', /json/); } describe('Testing standard REST endpoints-(CREATE, GET,PUT, DELETE)', function() { //This suite tests the CREATE functionality var ptOneID; var lat1 =chance.latitude({fixed: 7, min: 41, max: 42}); var lng1 = chance.longitude({fixed:7, min: -88, max:-87}); it('should post a new point', function(done) { var pt1 = new app.loopback.GeoPoint({lat: lat1, lng: lng1}); json('post', '/api/Points') .send({ location: pt1, }) .expect(200) .end(function(err, res) { ptOneID= res.body.id; done(); }); }); //This test preforms a put with out an id-- an upsert var lat5 =chance.latitude({fixed: 7, min: 41, max: 42}); var lng5 = chance.longitude({fixed:7, min: -88, max:-87}); var ptTwoID it('should preform an UPSERT since were not specifying ID', function(done) { var pt5 = new app.loopback.GeoPoint({lat: lat5, lng: lng5}); json( 'put','/api/Points/' ) .send({ location: pt5, }) .end(function(err, res) { var updatedPoint = res.body; ptTwoID = updatedPoint.id; done(); }) }); it('should return a list of all points', function(done) { json('get', '/api/Points') .expect(200) .end(function(err, res) { var points = res.body; assert(Array.isArray(points)); assert.equal(points.length, 2, 'array length incorrect'); done(); }); }); //originally I didnt have the delete tests wrapped in a describe I added it to see if it changed anything describe('DELETE has its own suite', function() { //Delete the point it('should DELETE the Point created by our POST test', function(done){ json('del', '/api/Points/' + ptOneID) .end(function(err, res) { assert.equal(res.status, 204, 'delete failed'); done(); }) }); it('should DELETE the Point we upserted',function(done){ json('del', '/api/Points'+ ptTwoID) .end(function(err, res) { assert.equal(res.status, 204, 'upsert delete failed'); done(); }); }); it('testing to see if posted point is still there', function(done){ json('get', '/api/Points/' + ptOneID) .end(function(err, res) { assert.equal(res.status, 404, 'posted point not deleted unsure emoticon'); done(); }) }); //this part was originally wrapped in an after hook, and worked perfectly until I added the describe for custom endpoints it('testing to see if upserted point is still there', function(done){ json('get', '/api/Points/' + ptTwoID) .end(function(err, res) { assert.equal(res.status, 404, 'upserted pt not deleted unsure emoticon'); done(); }) }); }); }); //This suite tests the beforeSave behavior describe('Testing Custom endpt', function() { blah blah blh }); 

最后一个有趣的事情:当我尝试做upsert删除,删除返回一个404,意思是没有find,但获取返回200状态,这意味着它被成功find。 请让我知道这里发生了什么。