Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e367b74

Browse filesBrowse 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 <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent a24264e commit e367b74
Copy full SHA for e367b74

File tree

Expand file treeCollapse file tree

1 file changed

+13
-8
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+13
-8
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-http-write-head.js
+13-8Lines changed: 13 additions & 8 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.