0

I have a method where I am using Node.js pipeline() that is having a last argument for a callback.

doSomething(readStream, destinationwritableStream): void {
   pipeline(readStream, destinationwritableStream, async () => {
      // some code here.
      // unable to cover this code using JEST
   })
}

Any suggestions, how I can cover this async() callback or how to mock pipeline() method.

Thanks in advance.

Nishant
  • 155
  • 11

1 Answers1

1

you can mock it like that:

jest.mock('./../path/to/file/that/includes/pipeline');

const { pipeline } = require('./../path/to/file/that/includes/pipeline');


const pipelineMock = async () => {
  return true;
};

pipeline.mockImplementation(pipelineMock);
Waelsy123
  • 594
  • 2
  • 13