Search code examples
node.jsstreamjasminejasmine-nodeistanbul

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?


Solution

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

    stream.emit('error', new Error('OOPS'));