DuplexMock extends both WritableMock and ReadableMock.
If no source is provided, the DuplexMock will try to work in linked mode : the writer output will be linked to the reader input.
This special mode is only available if writer and reader are in same mode (object or buffer).
example
import { DuplexMock } from'stream-mock';
// Not linkedconst duplex = new DuplexMock([1, 2, 3], { objectMode: true });
duplex.write(7, err => {
if(!err) {
const res = duplex.read() // res == 1
}
})
//Linkedconst lduplex = new DuplexMock(null, { objectMode: true });
lduplex.write(7, err => {
if(!err) {
const res = duplex.read() // res == 7
}
})
DuplexMock extends both WritableMock and ReadableMock. If no source is provided, the DuplexMock will try to work in linked mode : the writer output will be linked to the reader input. This special mode is only available if writer and reader are in same mode (object or buffer).
import { DuplexMock } from 'stream-mock'; // Not linked const duplex = new DuplexMock([1, 2, 3], { objectMode: true }); duplex.write(7, err => { if(!err) { const res = duplex.read() // res == 1 } }) //Linked const lduplex = new DuplexMock(null, { objectMode: true }); lduplex.write(7, err => { if(!err) { const res = duplex.read() // res == 7 } })