1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
'use strict'
var server = require('./server')
var request = require('../index')
var tape = require('tape')
var destroyable = require('server-destroy')
var s = server.createServer()
destroyable(s)
tape('setup', function (t) {
s.listen(0, function () {
s.on('/options', function (req, res) {
res.writeHead(200, {
'x-original-method': req.method,
'allow': 'OPTIONS, GET, HEAD'
})
res.end()
})
t.end()
})
})
tape('options(string, function)', function (t) {
request.options(s.url + '/options', function (err, res) {
t.equal(err, null)
t.equal(res.statusCode, 200)
t.equal(res.headers['x-original-method'], 'OPTIONS')
t.end()
})
})
tape('options(object, function)', function (t) {
request.options({
url: s.url + '/options',
headers: { foo: 'bar' }
}, function (err, res) {
t.equal(err, null)
t.equal(res.statusCode, 200)
t.equal(res.headers['x-original-method'], 'OPTIONS')
t.end()
})
})
tape('cleanup', function (t) {
s.destroy(function () {
t.end()
})
})
|