无法使用mocha和supertest测试OPTIONS方法

时间:2015-08-21 19:26:02

标签: javascript node.js testing mocha supertest

相关问题Cant test DELETE method using mocha and supertest及其目前的两个答案并未解决我的问题:(

以下是测试定义:

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

我已经尝试过很多东西而无法完成这项工作。

我使用的是超级^1.0.1,它在版本~0.13.0下运行良好。

https://github.com/visionmedia/supertest/issues/272

的相关问题

由于

1 个答案:

答案 0 :(得分:0)

我已经检测到了这个问题,我在API中返回了一个带有Content-Type: application/json的OPTIONS响应,但是主体是一个无效的JSON(它是GET,HEAD)。