node: fix test-net-connect-options-invalid.js (#17824)

This commit is contained in:
Meghan Denny
2025-03-03 21:57:13 -08:00
committed by GitHub
parent 2d0cadc949
commit 99d85be529
2 changed files with 34 additions and 0 deletions

View File

@@ -517,6 +517,13 @@ const Socket = (function (InternalSocket) {
...opts
} = options || {};
if (options?.objectMode)
throw $ERR_INVALID_ARG_VALUE("options.objectMode", options.objectMode, "is not supported");
if (options?.readableObjectMode)
throw $ERR_INVALID_ARG_VALUE("options.readableObjectMode", options.readableObjectMode, "is not supported");
if (options?.writableObjectMode)
throw $ERR_INVALID_ARG_VALUE("options.writableObjectMode", options.writableObjectMode, "is not supported");
super({
...opts,
allowHalfOpen,

View File

@@ -0,0 +1,27 @@
'use strict';
require('../common');
const assert = require('assert');
const net = require('net');
{
const invalidKeys = [
'objectMode',
'readableObjectMode',
'writableObjectMode',
];
invalidKeys.forEach((invalidKey) => {
const option = {
port: 8080,
[invalidKey]: true
};
const message = `The property 'options.${invalidKey}' is not supported. Received true`;
assert.throws(() => {
net.createConnection(option);
}, {
code: 'ERR_INVALID_ARG_VALUE',
name: 'TypeError',
message: new RegExp(message)
});
});
}