1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const http = require('http'); 5const Countdown = require('../common/countdown'); 6 7const expectedSuccesses = [undefined, null, 'GET', 'post']; 8const expectedFails = [-1, 1, 0, {}, true, false, [], Symbol()]; 9 10const countdown = 11 new Countdown(expectedSuccesses.length, 12 common.mustCall(() => server.close())); 13 14const server = http.createServer(common.mustCall((req, res) => { 15 res.end(); 16 countdown.dec(); 17}, expectedSuccesses.length)); 18 19server.listen(0, common.mustCall(() => { 20 expectedFails.forEach((method) => { 21 assert.throws(() => { 22 http.request({ method, path: '/' }, common.mustNotCall()); 23 }, { 24 code: 'ERR_INVALID_ARG_TYPE', 25 name: 'TypeError', 26 message: 'The "options.method" property must be of type string.' + 27 common.invalidArgTypeHelper(method) 28 }); 29 }); 30 31 expectedSuccesses.forEach((method) => { 32 http.request({ method, port: server.address().port }).end(); 33 }); 34})); 35