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
感謝
我無法複製。你確定你的API的迴應是有效的嗎? – robertklep
@robertklep感謝您的評論,它對於檢測問題非常有用。 – diosney