2015-08-21 62 views
0

的相关问题Cant test DELETE method using mocha and supertest和当前两个答案没有解决我的问题:(不能测试选项方法和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 

我已经尝试了很多东西,而能够使这项工作。

我正在使用supertest ^1.0.1,它与~0.13.0版本一起工作良好。

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

感谢

+0

我无法复制。你确定你的API的回应是有效的吗? – robertklep

+0

@robertklep感谢您的评论,它对于检测问题非常有用。 – diosney

回答

0

我已经检测到的问题相关的问题,它的API在我回国与Content-Type: application/json一个OPTIONS响应,但身体是一个无效的JSON(它是GET,HEAD )。