Sails.js和Mocha:使用supertest:path问题,当控制器在像api \ controllers这样的coustom文件夹被移动到api \ controllers \ admin

而我正在做testing代码,如果我把控制器在默认位置“API \控制器\”。 它运行完美没有错误,但是当我将其更改为'api \ controllers \ admin \'。 它给错误。

==>当控制器在默认位置“API \控制器\”

我的代码是在config / routes.js

'post /state/create': 'StateController.create', 

和testing代码是

 var request = require('supertest'); describe('StateController', function() { describe('#create()', function() { it('State already in table /create', function (done) { request(sails.hooks.http.app) .post('/state/create/') //Path and method .send({ name: 'gujarat', country_id: '55d452f20424cda40df0f3de' }) .set('Accept', 'application/json') .expect('Content-Type', /json/) .expect(800) .end(function(err, res){ if (err) throw err; console.log(res.body); if(res){ if(res.body.message == 'State already in table'){ done(); } } }); }); }); }); 

我得到了成功的结果

  StateController #create() { flag: false, data: 'gujarat', message: 'State already in table', code: 800 } √ State already in table /create (171ms) 

==>但是当我把控制器的位置改为'api \ controllers \ admin \'

route.js

 'post /admin/state/create': 'admin/StateController.create', 

并在testing代码

 .post('/state/create/') 

 .post('/admin/state/create/') 

我有错误

 1) StateController #create() State already in table /create: Uncaught TypeError: Cannot read property 'header' of undefined at Test._assertHeader (D:\Sails Projects\InterJewel\IJ\node_modules\supertest\lib\test.js:208:19) at Test._assertFunction (D:\Sails Projects\InterJewel\IJ\node_modules\supertest\lib\test.js:247:11) at Test.assert (D:\Sails Projects\InterJewel\IJ\node_modules\supertest\lib\test.js:148:18) at Server.assert (D:\Sails Projects\InterJewel\IJ\node_modules\supertest\lib\test.js:127:12) at net.js:1392:10 

参考链接 – http://sailsjs.org/documentation/concepts/testing