GIV
GIV

Reputation: 425

React Native - Jest testing with firebase

I am a newbie in Firebase. I have read that it is good to unit test as you go. So this is what I have been trying to do lately. I currently have a problem when trying to test render on a class that uses Firebase. This is the following code I have been trying to fix:

import 'react-native';
import React from 'react';
import MainTab from '../../components/MainTab';
import Enzyme from 'enzyme';

import renderer from 'react-test-renderer';

it('renders correctly', () => {
  const tree = renderer.create(
    <MainTab/>
    ).toJSON();
  expect(tree).toMatchSnapshot();
});

However, I am getting the following error on the test when trying to obtain the current user's id from firebase: enter image description here

Has anyone stumbled into this error before? P.S. Don't go hard on me if this is something really vacuous, just trying to learn.

Upvotes: 1

Views: 928

Answers (1)

Francis Batista
Francis Batista

Reputation: 1520

1. signInWithEmailAndPassword

signInWithEmailAndPassword(email, password) returns firebase.Promise containing non-null firebase.User

Asynchronously signs in using an email and password.

This method will be deprecated and will be updated to resolve with a firebase.auth.UserCredential as is returned in firebase.auth.Auth#signInAndRetrieveDataWithEmailAndPassword.

For now, the implementation for this method is in below:

firebase.auth().signInWithEmailAndPassword(email, password).then(function(user) {
   // user signed in
   // - user.displayName
   // - user.email
   // - user.uid // <---- the user's unique ID
})

2. For your case...

If you need to test the email/password authentication, I suggest you to use a firebase "dev" project and testing with user credentials for this dev firebase project.

  • Be careful, don't store your UID for other tests!
  • Firebase dont't provides a test for authentication yet.

3. Firebase beta to 1.0 version

Easier unit testing using a new firebase-functions-test npm module that simplifies writing unit tests.

See more about it in:

I hope I have been useful!

Upvotes: 1

Related Questions