与此[question] [1]相关,我正在尝试进行单元测试时模拟firestore。
我尝试模拟的代码如下所示:
const firestore = admin.firestore();
const users = await firestore.collection('users').get();
Run Code Online (Sandbox Code Playgroud)
而我尝试模拟它的过程如下:
const firestoreStub = sinon.stub();
Object.defineProperty(admin, 'firestore', {
get: () => {
return {
collection: (path) => Promise.resolve({mocka: 'user'})
}
}
});
Run Code Online (Sandbox Code Playgroud)
但是,它不起作用。
我创建了一个仓库(官方功能仓库的克隆),如果有帮助,请在此处给出整个示例。
javascript firebase google-cloud-functions google-cloud-firestore