node/test/parallel/test-net-write-arguments.js
Robert Nagy 75b30c606c stream: emit 'error' asynchronously
errorOrDestroy emits 'error' synchronously due to
compat reasons. However, it should be possible to
use correct async behaviour for new code.

PR-URL: https://github.com/nodejs/node/pull/29744
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2020-01-04 16:20:45 -08:00

39 lines
946 B
JavaScript

'use strict';
const common = require('../common');
const net = require('net');
const socket = net.Stream({ highWaterMark: 0 });
// Make sure that anything besides a buffer or a string throws.
socket.write(null, common.expectsError({
code: 'ERR_STREAM_NULL_VALUES',
name: 'TypeError',
message: 'May not write null values to stream'
}));
socket.on('error', common.expectsError({
code: 'ERR_STREAM_NULL_VALUES',
name: 'TypeError',
message: 'May not write null values to stream'
}));
[
true,
false,
undefined,
1,
1.0,
+Infinity,
-Infinity,
[],
{}
].forEach((value) => {
// We need to check the callback since 'error' will only
// be emitted once per instance.
socket.write(value, common.expectsError({
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "chunk" argument must be of type string or an instance of ' +
`Buffer.${common.invalidArgTypeHelper(value)}`
}));
});