diff --git a/test/parallel/test-http-socket-encoding-error.js b/test/parallel/test-http-socket-encoding-error.js new file mode 100644 index 00000000000000..cfb96f4f81bc2e --- /dev/null +++ b/test/parallel/test-http-socket-encoding-error.js @@ -0,0 +1,23 @@ +'use strict'; + +const common = require('../common'); +const http = require('http'); + +const server = http.createServer().listen(0, connectToServer); + +server.on('connection', (socket) => { + common.expectsError(() => socket.setEncoding(''), + { + code: 'ERR_METHOD_NOT_IMPLEMENTED', + type: Error + }); + + socket.end(); +}); + +function connectToServer() { + const client = new http.Agent().createConnection(this.address().port, () => { + client.end(); + }) + .on('end', () => server.close()); +}