Simulating stream `error` event for tests
Asked Answered
C

1

8

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?

Cloudland answered 18/10, 2015 at 5:31 Comment(3)
Why not just emit an error event on the stream?: stream.emit('error', new Error('OOPS'));Skell
@mscdex, why not publish it as an answer? :)Cloudland
@mscdex, I have tried it, and it worked. Thank you! Do you want to publish it as an answer?Cloudland
S
17

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

stream.emit('error', new Error('OOPS'));
Skell answered 18/10, 2015 at 7:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.