【发布时间】:2019-12-25 05:55:44
【问题描述】:
您能否分享一些用于 firebase-admin 身份验证的 Sinon 存根示例。挑战在于初始化 Firebase 管理应用程序以获取更多存根。
我尝试了下一个代码
const admin = require('firebase-admin');
sinon.stub(admin, 'initializeApp');
var noUserError = new Error('error');
noUserError.code = 'auth/user-not-found';
sinon.stub(admin, 'auth').returns({
getUserByEmail: sinon.fake.rejects(noUserError)
});
var err = await admin.auth().getUserByEmail(email);
console.error(err);
但它会返回
Error (FirebaseAppError) {
codePrefix: 'app',
errorInfo: {
code: 'app/no-app',
message: 'The default Firebase app does not exist. Make sure you call initializeApp() before using any of the Firebase services.',
},
message: 'The default Firebase app does not exist. Make sure you call initializeApp() before using any of the Firebase services.',
}
预期结果是异常 Error with code = 'auth/user-not-found'
【问题讨论】:
标签: node.js firebase-authentication sinon