Skip to content

Commit

Permalink
test: handle empty responses to HEAD requests
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Apr 30, 2018
1 parent d672afe commit 522bf07
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions test/issues/841-head-request-test.js
@@ -0,0 +1,47 @@
const nock = require('nock')
const Octokit = require('../../')

require('../mocha-node-setup')

describe('https://github.com/octokit/rest.js/issues/841', () => {
it('supports sending GET requests with method: HEAD', () => {
nock('https://head-request-test.com')
.head('/repos/whatwg/html/pulls/1')
.query(true)
// GitHub API returns 200 and Content-{Type|Length} headers for HEAD requsets
.reply(200, '', {
'Content-Type': 'application/json; charset=utf-8',
'Content-Length': 19137
})
.head('/repos/whatwg/html/pulls/2')
.query(true)
.reply(404, '', {
'Content-Type': 'application/json; charset=utf-8',
'Content-Length': 120
})

const client = new Octokit({
baseUrl: 'https://head-request-test.com'
})

client.pullRequests.get({
method: 'head',
owner: 'whatwg',
repo: 'html',
number: 1
})

.then(() => {
return client.pullRequests.get({
method: 'head',
owner: 'whatwg',
repo: 'html',
number: 2
})

.catch((error) => {
expect(error.code).to.equal(404)
})
})
})
})

0 comments on commit 522bf07

Please sign in to comment.