Javascript Can';使用摩卡和supertest的t测试选项方法

Javascript Can';使用摩卡和supertest的t测试选项方法,javascript,node.js,testing,mocha.js,supertest,Javascript,Node.js,Testing,Mocha.js,Supertest,相关问题及其当前的两个答案并没有解决我的问题:( 以下是测试定义: api = supertest(url); describe('when OPTIONS', function () { it('should return only method GET', function (done) { api .options('/') .expect('Allow', 'GET') .expect(200, done);

相关问题及其当前的两个答案并没有解决我的问题:(

以下是测试定义:

api = supertest(url);

describe('when OPTIONS', function () {
    it('should return only method GET', function (done) {
      api
        .options('/')
        .expect('Allow', 'GET')
        .expect(200, done);
    });
  });
它不断触发以下错误:

Uncaught TypeError: Cannot read property 'header' of undefined
      at _stream_readable.js:944:16
以及何时:

 api
        .options('/')
        .end(function(error,res){
          if (error) return done(error);
          done()
        });
它说:

SyntaxError: Unexpected token G
      at Object.parse (native)
      at _stream_readable.js:944:16
我已经尝试了很多东西,但都没有成功

我正在使用supertest
^1.0.1
,它在版本
~0.13.0
中运行良好

相关问题在


感谢

我已经检测到了这个问题,就是在API中我返回了一个选项响应,内容类型为
Content-Type:application/json
,但是主体是一个无效的json(它是GET,HEAD).

我已经检测到了这个问题,就是在API中我返回了一个选项响应,内容类型为:application/json,但是主体是一个无效的json(它是GET,HEAD).

我无法复制。您确定API的响应有效吗?@robertklep感谢您的评论,这对检测问题非常有用。我无法复制。您确定API的响应有效吗?@robertklep感谢您的评论,这对检测问题非常有用。