0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-http-expect-handling.js
Gibson Fahnestock 3d2aef3979 test: s/assert.equal/assert.strictEqual/
Use assert.strictEqual instead of assert.equal in tests, manually
convert types where necessary.

PR-URL: https://github.com/nodejs/node/pull/10698
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
2017-01-11 14:19:26 +00:00

56 lines
1.2 KiB
JavaScript

// Spec documentation http://httpwg.github.io/specs/rfc7231.html#header.expect
'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');
const tests = [417, 417];
let testsComplete = 0;
let testIdx = 0;
const s = http.createServer(function(req, res) {
throw new Error('this should never be executed');
});
s.listen(0, nextTest);
function nextTest() {
const options = {
port: s.address().port,
headers: { 'Expect': 'meoww' }
};
if (testIdx === tests.length) {
return s.close();
}
const test = tests[testIdx];
if (testIdx > 0) {
s.on('checkExpectation', common.mustCall((req, res) => {
res.statusCode = 417;
res.end();
}));
}
http.get(options, function(response) {
console.log('client: expected status: ' + test);
console.log('client: statusCode: ' + response.statusCode);
assert.strictEqual(response.statusCode, test);
assert.strictEqual(response.statusMessage, 'Expectation Failed');
response.on('end', function() {
testsComplete++;
testIdx++;
nextTest();
});
response.resume();
});
}
process.on('exit', function() {
assert.strictEqual(2, testsComplete);
});