test: add an exception test to http-write-head
* Add an exception test. * Add `common.mustCall()`. * Make use of Arrow function. PR-URL: https://github.com/nodejs/node/pull/11034 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
0d290a2ae0
commit
49e5f61ef6
@ -1,12 +1,12 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
|
|
||||||
// Verify that ServerResponse.writeHead() works as setHeader.
|
// Verify that ServerResponse.writeHead() works as setHeader.
|
||||||
// Issue 5036 on github.
|
// Issue 5036 on github.
|
||||||
|
|
||||||
const s = http.createServer(function(req, res) {
|
const s = http.createServer(common.mustCall((req, res) => {
|
||||||
res.setHeader('test', '1');
|
res.setHeader('test', '1');
|
||||||
|
|
||||||
// toLowerCase() is used on the name argument, so it must be a string.
|
// toLowerCase() is used on the name argument, so it must be a string.
|
||||||
@ -32,18 +32,23 @@ const s = http.createServer(function(req, res) {
|
|||||||
assert.ok(threw, 'Undefined value should throw');
|
assert.ok(threw, 'Undefined value should throw');
|
||||||
|
|
||||||
res.writeHead(200, { Test: '2' });
|
res.writeHead(200, { Test: '2' });
|
||||||
res.end();
|
|
||||||
});
|
|
||||||
|
|
||||||
s.listen(0, runTest);
|
assert.throws(() => {
|
||||||
|
res.writeHead(100, {});
|
||||||
|
}, /^Error: Can't render headers after they are sent to the client$/);
|
||||||
|
|
||||||
|
res.end();
|
||||||
|
}));
|
||||||
|
|
||||||
|
s.listen(0, common.mustCall(runTest));
|
||||||
|
|
||||||
function runTest() {
|
function runTest() {
|
||||||
http.get({ port: this.address().port }, function(response) {
|
http.get({ port: this.address().port }, common.mustCall((response) => {
|
||||||
response.on('end', function() {
|
response.on('end', common.mustCall(() => {
|
||||||
assert.strictEqual(response.headers['test'], '2');
|
assert.strictEqual(response.headers['test'], '2');
|
||||||
assert.notStrictEqual(response.rawHeaders.indexOf('Test'), -1);
|
assert.notStrictEqual(response.rawHeaders.indexOf('Test'), -1);
|
||||||
s.close();
|
s.close();
|
||||||
});
|
}));
|
||||||
response.resume();
|
response.resume();
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user