繁体   English   中英

使用 Jest 模拟 Node.js stream 管道

[英]Mock Node.js stream pipeline using Jest

我有一个方法,我正在使用 Node.js pipeline(),它有一个回调的最后一个参数。

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

任何建议,我如何涵盖此 async() 回调或如何模拟 pipeline() 方法。

提前致谢。

你可以这样模拟它:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM