【问题标题】:Firebase Jest auth/network-request-failed' errorFirebase Jest auth/network-request-failed' 错误
【发布时间】: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


【解决方案1】:

我也有这个问题,我找了谷歌,发现我在 html 中的输入或按​​钮是 type:"submit" 这使页面刷新,最好是 type"button"

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2016-12-16
  • 2017-08-31
  • 2016-10-12
  • 1970-01-01
  • 2021-07-15
  • 2023-03-29
  • 2019-04-02
  • 2020-08-02
相关资源
最近更新 更多