test for options support

This commit is contained in:
David Frank 2016-03-19 18:24:08 +08:00
parent 362aa087ca
commit 9a90e7d0b9
2 changed files with 19 additions and 0 deletions

View File

@ -41,6 +41,12 @@ TestServer.prototype.router = function(req, res) {
res.end('text');
}
if (p === '/options') {
res.statusCode = 200;
res.setHeader('Allow', ['GET', 'HEAD', 'OPTIONS']);
res.end('hello world');
}
if (p === '/html') {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/html');

View File

@ -607,6 +607,19 @@ describe('node-fetch', function() {
});
});
it('should allow OPTIONS request', function() {
url = base + '/options';
opts = {
method: 'OPTIONS'
};
return fetch(url, opts).then(function(res) {
expect(res.status).to.equal(200);
expect(res.statusText).to.equal('OK');
expect(res.headers.get('allow')).to.equal('GET, HEAD, OPTIONS');
expect(res.body).to.be.an.instanceof(stream.Transform);
});
});
it('should reject decoding body twice', function() {
url = base + '/plain';
return fetch(url).then(function(res) {