简体   繁体   中英

Firebase Jest auth/network-request-failed' error

I'm trying to do Firebase testing Using Jest. This is my test case.

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');});
};

When I run the test with Idea-Webstorm-Jest Plugin it Works. (Test passes.) But when I try with npm Test command. Firebase gives me following Error.

{code: 'auth.network-request-failed', message: 'A.network error (such as timeout, interrupted connection or unreachable host) has occurred.' }

So why it is fails when npm Test command runs? Anyone can help me? thanks in advance.

I had that problem too, i looked for google and i found that my input or button in html was in type:"submit" which made the page refresh, it's better to do type"button"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM