【发布时间】:2021-12-27 07:41:45
【问题描述】:
test.wrapped(function) 和 function.run() 有什么区别?两者似乎都在本地测试运行器下运行良好。我使用了 mocha,但我认为它在 jest 下也会以相同的方式运行。
以下两种方法有什么区别?
1.直接调用:
.....
.....
.....
funcName.run({foo:"bar"}, { auth: { uid: "ABC" } });
.....
.....
.....
2。 [间接调用] 使用 wrap:
.....
.....
.....
const projectConfig = {
projectId: 'my-project',
databaseURL: 'https://my-project.firebaseio.com'
};
const test = require('firebase-functions-test')(projectConfig, './service-account-key.json');
wrapped = test.wrap(funcName);
expect(
wrapped(
{ foo: "bar" },
{ auth: { uid: "ABC" } }
)
).to.contain('foobar');
.....
.....
.....
我们是否需要使用 test.wrap() 来利用测试运行器的额外功能?这也可以通过 async await 来实现,但是上面提到的使用起来会很方便。例如。 eventually 来自 chai-as-promised 的承诺?
【问题讨论】:
-
嗨@Mehul Pamale,如果您认为我的回答对您有所帮助,请考虑通过单击投票箭头下方左侧的复选标记并投票来接受它。非常感谢,谢谢!
-
完成!谢谢您的回答。欣赏!
标签: javascript firebase google-cloud-firestore google-cloud-functions