Reputation: 425
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:
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
Reputation: 1520
signInWithEmailAndPassword(email, password)
returnsfirebase.Promise
containing non-nullfirebase.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
})
You can see firebase.User
properties here:
https://firebase.google.com/docs/reference/js/firebase.User
You can read more details about this question here https://stackoverflow.com/a/39959002/3332734
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.
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