Skip to content

Commit 22d4ed2

Browse files
hiroppyMylesBorins
authored andcommitted
test: add an exception test to http-write-head
* Add an exception test. * Add `common.mustCall()`. * Make use of Arrow function. PR-URL: #11034 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 9edd342 commit 22d4ed2

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

test/parallel/test-http-write-head.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
'use strict';
2-
require('../common');
3-
var assert = require('assert');
4-
var http = require('http');
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const http = require('http');
55

66
// Verify that ServerResponse.writeHead() works as setHeader.
77
// Issue 5036 on github.
88

9-
var s = http.createServer(function(req, res) {
9+
const s = http.createServer(common.mustCall((req, res) => {
1010
res.setHeader('test', '1');
1111

1212
// toLowerCase() is used on the name argument, so it must be a string.
@@ -31,18 +31,23 @@ var s = http.createServer(function(req, res) {
3131
assert.ok(threw, 'Undefined value should throw');
3232

3333
res.writeHead(200, { Test: '2' });
34+
35+
assert.throws(() => {
36+
res.writeHead(100, {});
37+
}, /^Error: Can't render headers after they are sent to the client$/);
38+
3439
res.end();
35-
});
40+
}));
3641

37-
s.listen(0, runTest);
42+
s.listen(0, common.mustCall(runTest));
3843

3944
function runTest() {
40-
http.get({ port: this.address().port }, function(response) {
41-
response.on('end', function() {
42-
assert.equal(response.headers['test'], '2');
45+
http.get({ port: this.address().port }, common.mustCall((response) => {
46+
response.on('end', common.mustCall(() => {
47+
assert.strictEqual(response.headers['test'], '2');
4348
assert.notStrictEqual(response.rawHeaders.indexOf('Test'), -1);
4449
s.close();
45-
});
50+
}));
4651
response.resume();
47-
});
52+
}));
4853
}

0 commit comments

Comments
 (0)