Skip to content

Commit

Permalink
test: add test for writable.write() argument types
Browse files Browse the repository at this point in the history
PR-URL: #29746
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
ronag authored and BridgeAR committed Oct 9, 2019
1 parent 79f6cd3 commit bf1727a
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/parallel/test-stream-writable-invalid-chunk.js
Original file line number Diff line number Diff line change
@@ -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');

0 comments on commit bf1727a

Please sign in to comment.