【发布时间】:2017-10-23 16:13:20
【问题描述】:
我正在尝试使用 Jest 进行 Firebase 测试。这是我的测试用例。
test('Test Firebase Connection', done => {
let history = [];
function callback(history) {
expect(history[0]).toBe('/dashboard');
done();
}
firebaseDAO.init('myEmail', 'mypassword', history);
setTimeout(callback, 4000,history);
});
export const init = (username, passwordPassed, history) => {
let historyData = history;
const email = username;
const password = passwordPassed;
const auth = firebase.auth();
const promise = auth.signInWithEmailAndPassword(email, password);
promise.catch(e => console.log(e));
promise.then(() => {historyData.push('/dashboard');});
};
当我使用 Idea-Webstorm-Jest 插件运行测试时,它可以工作。 (测试通过。)
但是当我尝试使用npm Test 命令时。 Firebase 给了我以下错误。
{code: 'auth/network-request-failed', message: '发生了网络错误(例如超时、连接中断或主机无法访问)。' }
那么为什么npm Test 命令运行时会失败?任何人都可以帮助我吗?提前致谢。
【问题讨论】:
-
我也有同样的错误,你找到解决办法了吗?
-
是的,我将 package.json 中“脚本”中的“测试”更改为如下所示。 "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "CI=true react-scripts test", "eject": "react-scripts 弹出" } 并尝试 npm test 它工作。
标签: reactjs firebase firebase-authentication jestjs