summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRobert Nagy <ronagy@icloud.com>2019-09-28 09:48:33 +0200
committerRich Trott <rtrott@gmail.com>2019-10-03 12:30:39 -0700
commit6ea51bc4918c05e293c30d5efc384a15ae6cfd7e (patch)
tree37307d7f76d92daf6fe6798b3bb12b32cd34d1bb /test
parent88ef086e39cd055a1cdc6720981f50e4791fb90f (diff)
downloadandroid-node-v8-6ea51bc4918c05e293c30d5efc384a15ae6cfd7e.tar.gz
android-node-v8-6ea51bc4918c05e293c30d5efc384a15ae6cfd7e.tar.bz2
android-node-v8-6ea51bc4918c05e293c30d5efc384a15ae6cfd7e.zip
test: add test for writable.write() argument types
PR-URL: https://github.com/nodejs/node/pull/29746 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-stream-writable-invalid-chunk.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/test/parallel/test-stream-writable-invalid-chunk.js b/test/parallel/test-stream-writable-invalid-chunk.js
new file mode 100644
index 0000000000..09ee5877c8
--- /dev/null
+++ b/test/parallel/test-stream-writable-invalid-chunk.js
@@ -0,0 +1,35 @@
+'use strict';
+
+const common = require('../common');
+const stream = require('stream');
+
+function testWriteType(val, objectMode, code) {
+ const writable = new stream.Writable({
+ objectMode,
+ write: () => {}
+ });
+ if (!code) {
+ writable.on('error', common.mustNotCall());
+ } else {
+ writable.on('error', common.expectsError({
+ code: code,
+ }));
+ }
+ writable.write(val);
+}
+
+testWriteType([], false, 'ERR_INVALID_ARG_TYPE');
+testWriteType({}, false, 'ERR_INVALID_ARG_TYPE');
+testWriteType(0, false, 'ERR_INVALID_ARG_TYPE');
+testWriteType(true, false, 'ERR_INVALID_ARG_TYPE');
+testWriteType(0.0, false, 'ERR_INVALID_ARG_TYPE');
+testWriteType(undefined, false, 'ERR_INVALID_ARG_TYPE');
+testWriteType(null, false, 'ERR_STREAM_NULL_VALUES');
+
+testWriteType([], true);
+testWriteType({}, true);
+testWriteType(0, true);
+testWriteType(true, true);
+testWriteType(0.0, true);
+testWriteType(undefined, true);
+testWriteType(null, true, 'ERR_STREAM_NULL_VALUES');