我用火力3.3.0,我想用signInWithEmailAndPassword功能在我的摩卡单元测试,但我得到的错误认证/网络请求失败摩卡单元测试火力地堡应用
Unhandled rejection Error: A network error (such as timeout, interrupted connection or unreachable host) has occurred.
测试.js文件
const FIREBASE_CONFIG = {
apiKey: "AIzaSyDdA1POUWy9eid1AdBYuMdxch_k8ob7Qrg",
authDomain: "my-app.firebaseapp.com",
databaseURL: "https://my-app.firebaseio.com",
storageBucket: "my-app.appspot.com",
};
const FIREBASE_API_REF = firebase.initializeApp(FIREBASE_CONFIG);
before(function (done) {
promise = new Promise(function (resolve, reject) {
return FIREBASE_API_REF.auth().signInWithEmailAndPassword(firstUserEmail, firstUserPassword)
.then(function (userData) {
firstUserId = userData.uid;
resolve(userData);
done();
}, function (error) {
return reject(error);
})
});
});
的package.json
"scripts": {
"test": "mocha --grep ./e2e.js --invert --compilers js:babel-register -R spec --ui bdd --timeout 7000"
}
您将需要显示“FIREBASE_API_REF”引用的内容。此外,代码还存在其他问题:'done'永远不会被调用;决不会被称为;你不需要创建自己的承诺 - 这是一个[反模式](https://github.com/petkaantonov/bluebird/wiki/Promise-anti-patterns#the-deferred-anti-pattern)。 – cartant
@cartant感谢您的回复,这不是'before'函数的完整部分。我只是想显示一段代码,我不能调用'signInWithEmailAndPassword'函数。请看我编辑的问题。 – Matt
我认为这个问题的部分问题是不清楚你在问什么,并且你已经剪掉了部分测试代码 - “describe”和“it”调用在哪里?另外,您还没有指定如何运行测试:在使用Karma的浏览器中;或者在Node中使用mocha命令? – cartant