Skip to content

Commit bf1727a

Browse files
ronagBridgeAR
authored andcommittedOct 9, 2019
test: add test for writable.write() argument types
PR-URL: #29746 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 79f6cd3 commit bf1727a

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const stream = require('stream');
5+
6+
function testWriteType(val, objectMode, code) {
7+
const writable = new stream.Writable({
8+
objectMode,
9+
write: () => {}
10+
});
11+
if (!code) {
12+
writable.on('error', common.mustNotCall());
13+
} else {
14+
writable.on('error', common.expectsError({
15+
code: code,
16+
}));
17+
}
18+
writable.write(val);
19+
}
20+
21+
testWriteType([], false, 'ERR_INVALID_ARG_TYPE');
22+
testWriteType({}, false, 'ERR_INVALID_ARG_TYPE');
23+
testWriteType(0, false, 'ERR_INVALID_ARG_TYPE');
24+
testWriteType(true, false, 'ERR_INVALID_ARG_TYPE');
25+
testWriteType(0.0, false, 'ERR_INVALID_ARG_TYPE');
26+
testWriteType(undefined, false, 'ERR_INVALID_ARG_TYPE');
27+
testWriteType(null, false, 'ERR_STREAM_NULL_VALUES');
28+
29+
testWriteType([], true);
30+
testWriteType({}, true);
31+
testWriteType(0, true);
32+
testWriteType(true, true);
33+
testWriteType(0.0, true);
34+
testWriteType(undefined, true);
35+
testWriteType(null, true, 'ERR_STREAM_NULL_VALUES');

0 commit comments

Comments
 (0)
Please sign in to comment.