相关问题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
我已经尝试了很多东西,但无法完成这项工作。
我正在使用 super 测试 ^1.0.1
,它在 ~0.13.0
版本上运行良好。
相关问题在 https://github.com/visionmedia/supertest/issues/272
谢谢
最佳答案
我已经检测到这个问题,我在 API 中返回了一个带有 Content-Type: application/json
的 OPTIONS 响应,但正文是一个无效的 JSON(它是 GET,HEAD) .
关于javascript - 无法使用 mocha 和 supertest 测试 OPTIONS 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32147948/