Skip to content
Advertisement

Javascript Mocking functions that return Readable

I have a simple function that calls my s3 service which will return a Promise

JavaScript

I would like to mock the return of the object and assert it in the test like this:

JavaScript

When i run the test, I face this error:

Error [ERR_METHOD_NOT_IMPLEMENTED]: The _read() method is not implemented at Readable.read (internal/streams/readable.js:642:9) at Readable.read (internal/streams/readable.js:481:10) at maybeReadMore (internal/streams/readable.js:629:12) at processTicksAndRejections (internal/process/task_queues.js:82:21) { code: ‘ERR_METHOD_NOT_IMPLEMENTED’

Would like some help on how I can properly mock a readable for example in this example

Advertisement

Answer

Your production code just forward response from the service to outside, then just mock getObject to return anything, and expect the result should be getObject result and the service function will have called with correct parameter:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement