2015-08-21 66 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 )。