[英]Cannot mock the constructor of the class in Node.js, TypeScript using Jest
[英]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.