Nishant
Nishant

Reputation: 157

Mock Node.js stream pipeline using Jest

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.

Upvotes: 0

Views: 1043

Answers (1)

Waelsy123
Waelsy123

Reputation: 612

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);

Upvotes: 1

Related Questions