我用火力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