Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuta Hiroto <git@about-hiroppy.com>2017-01-27 18:49:02 +0300
committerMyles Borins <myles.borins@gmail.com>2017-03-09 04:11:22 +0300
commit22d4ed248428cb416eb792ff2fa2a74d9c23ffa4 (patch)
treebbcca019f82456e908d60e0ec8cdda8b83dca64e
parent9edd342e81306d10be794dbb70ba5874d4ad8533 (diff)
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>
-rw-r--r--test/parallel/test-http-write-head.js27
1 files changed, 16 insertions, 11 deletions
diff --git a/test/parallel/test-http-write-head.js b/test/parallel/test-http-write-head.js
index 32fff6042e7..bdb5d906a00 100644
--- a/test/parallel/test-http-write-head.js
+++ b/test/parallel/test-http-write-head.js
@@ -1,12 +1,12 @@
'use strict';
-require('../common');
-var assert = require('assert');
-var http = require('http');
+const common = require('../common');
+const assert = require('assert');
+const http = require('http');
// Verify that ServerResponse.writeHead() works as setHeader.
// Issue 5036 on github.
-var s = http.createServer(function(req, res) {
+const s = http.createServer(common.mustCall((req, res) => {
res.setHeader('test', '1');
// toLowerCase() is used on the name argument, so it must be a string.
@@ -31,18 +31,23 @@ var s = http.createServer(function(req, res) {
assert.ok(threw, 'Undefined value should throw');
res.writeHead(200, { Test: '2' });
+
+ assert.throws(() => {
+ res.writeHead(100, {});
+ }, /^Error: Can't render headers after they are sent to the client$/);
+
res.end();
-});
+}));
-s.listen(0, runTest);
+s.listen(0, common.mustCall(runTest));
function runTest() {
- http.get({ port: this.address().port }, function(response) {
- response.on('end', function() {
- assert.equal(response.headers['test'], '2');
+ http.get({ port: this.address().port }, common.mustCall((response) => {
+ response.on('end', common.mustCall(() => {
+ assert.strictEqual(response.headers['test'], '2');
assert.notStrictEqual(response.rawHeaders.indexOf('Test'), -1);
s.close();
- });
+ }));
response.resume();
- });
+ }));
}