forked from request/request
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Abort request on form-data error and improve test
- Loading branch information
Showing
2 changed files
with
27 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,34 @@ | ||
'use strict' | ||
|
||
var request = require('../index') | ||
, server = require('./server') | ||
, tape = require('tape') | ||
|
||
function runTest(t) { | ||
var req | ||
, form | ||
, reqOptions = { | ||
url: 'http://localhost:8080/' | ||
} | ||
var s = server.createServer() | ||
|
||
req = request.post(reqOptions, function (err, res, body) { | ||
t.equal(err.message,'Arrays are not supported.') | ||
t.end() | ||
}) | ||
tape('setup', function(t) { | ||
s.listen(s.port, function() { | ||
t.end() | ||
}) | ||
}) | ||
|
||
form = req.form() | ||
form.append('field',['value1','value2']) | ||
} | ||
tape('re-emit formData errors', function(t) { | ||
s.on('/', function(req, res) { | ||
res.writeHead(400) | ||
res.end() | ||
t.fail('The form-data error did not abort the request.') | ||
}) | ||
|
||
request.post(s.url, function (err, res, body) { | ||
t.equal(err.message, 'form-data: Arrays are not supported.') | ||
setTimeout(function() { | ||
t.end() | ||
}, 10) | ||
}).form().append('field', ['value1', 'value2']) | ||
}) | ||
|
||
tape('re-emit formData errors', function(t) { | ||
runTest(t) | ||
tape('cleanup', function(t) { | ||
s.close(function() { | ||
t.end() | ||
}) | ||
}) |