Skip to content

Commit e367b74

Browse files
hiroppyevanlucas
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 a24264e commit e367b74

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

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

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
33
const assert = require('assert');
44
const http = require('http');
55

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

9-
const 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.
@@ -32,18 +32,23 @@ const s = http.createServer(function(req, res) {
3232
assert.ok(threw, 'Undefined value should throw');
3333

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

38-
s.listen(0, runTest);
43+
s.listen(0, common.mustCall(runTest));
3944

4045
function runTest() {
41-
http.get({ port: this.address().port }, function(response) {
42-
response.on('end', function() {
46+
http.get({ port: this.address().port }, common.mustCall((response) => {
47+
response.on('end', common.mustCall(() => {
4348
assert.strictEqual(response.headers['test'], '2');
4449
assert.notStrictEqual(response.rawHeaders.indexOf('Test'), -1);
4550
s.close();
46-
});
51+
}));
4752
response.resume();
48-
});
53+
}));
4954
}

0 commit comments

Comments
 (0)