【发布时间】:2020-01-08 05:25:41
【问题描述】:
我想为下面的代码存根模拟响应,我该怎么做?
import { Storage } from "@google-cloud/storage";
const storage = new Storage();
import a from "./a.js"
export function abc(req, res) {
a().then(result ->{
const bucketName = result.bucketName;
const fileName = "Sample.json";
const file = storage.bucket(bucketName).file(result.fileName);
const myfile = file.createReadStream();
let buffer = "";
myfile
.on("data", function(a) {
buffer += a;
})
.on("end", function() {
console.log(buffer);
res.status(200).send(buffer);
});
});
}
import a from "./a.js" 是异步函数,我需要使用 mocha chai 编写单元测试。
【问题讨论】:
-
您是否正确导出了 a.js 中的模块?看看这个tutorial。让我知道是否适合您。否则,我可以进一步帮助您。
-
是的,function const a= async () => { //逻辑返回结果 } module.exports = a;
标签: unit-testing google-cloud-functions sinon sinon-chai