Add readable, writable and duplex
This commit is contained in:
7
test/isReadableStream/isReadableStream.js
Normal file
7
test/isReadableStream/isReadableStream.js
Normal file
@ -0,0 +1,7 @@
|
||||
const isReadableStream = val =>
|
||||
val !== null &&
|
||||
typeof val === 'object' &&
|
||||
typeof val.pipe === 'function' &&
|
||||
typeof val._read === 'function' &&
|
||||
typeof val._readableState === 'object';
|
||||
module.exports = isReadableStream;
|
||||
20
test/isReadableStream/isReadableStream.test.js
Normal file
20
test/isReadableStream/isReadableStream.test.js
Normal file
@ -0,0 +1,20 @@
|
||||
const expect = require('expect');
|
||||
const isReadableStream = require('./isReadableStream.js');
|
||||
const fs = require('fs');
|
||||
const Stream = require('stream');
|
||||
|
||||
test('isReadableStream is a Function', () => {
|
||||
expect(isReadableStream).toBeInstanceOf(Function);
|
||||
});
|
||||
test('isReadableStream returns true for read streams', () => {
|
||||
expect(isReadableStream(fs.createReadStream('isReadableStream.js'))).toBeTruthy();
|
||||
});
|
||||
test('isReadableStream returns false for write streams', () => {
|
||||
expect(isReadableStream(fs.createWriteStream('isReadableStream.js'))).toBeFalsy();
|
||||
});
|
||||
test('isReadableStream returns true for duplex streams', () => {
|
||||
expect(isReadableStream(new Stream.Duplex())).toBeTruthy();
|
||||
});
|
||||
test('isReadableStream returns false for non-streams', () => {
|
||||
expect(isReadableStream({})).toBeFalsy();
|
||||
});
|
||||
Reference in New Issue
Block a user