Skip to content

Commit bf1727a

Browse files
ronagBridgeAR
authored andcommitted
test: add test for writable.write() argument types
PR-URL: #29746 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 79f6cd3 commit bf1727a

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
3+
constcommon=require('../common');
4+
conststream=require('stream');
5+
6+
functiontestWriteType(val,objectMode,code){
7+
constwritable=newstream.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)