Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulating stream `error` event for tests

I'm using the latest istanbul + jasmine-node to write all my test scripts.

In a few places I have a Readable stream that may emit error event, and I have no idea how to simulate such event in a test environment, to provide code coverage.

Can anybody suggest an idea of how to approach this, please?

like image 975
vitaly-t Avatar asked Oct 18 '15 05:10

vitaly-t


1 Answers

It should just be as simple as emitting an error directly on the object:

stream.emit('error', new Error('OOPS'));
like image 180
mscdex Avatar answered Oct 23 '22 00:10

mscdex