Reputation: 487
Does anyone know why this won't work?
My api call:
import firebase from 'react-native-firebase';
export default function getAuth() {
return new Promise((resolve) => {
firebase.auth().onAuthStateChanged((user) => {
resolve(user);
});
});
}
My unit test that fails on, "Expected one assertion to be called but received zero assertion calls".
import firebase from 'react-native-firebase';
import getAuth from '../'; // eslint-disable-line
jest.mock('react-native-firebase', () => {
return {
auth: () => {
return {
onAuthStateChanged: () => {
return Promise.resolve({
name: 'Shaun',
});
},
};
},
};
});
it('resolves a promise containing the user', async () => {
expect.assertions(1);
const response = await getAuth();
expect(response).toEqual({ name: 'Shaun' });
});
Upvotes: 2
Views: 1575
Reputation: 2932
onAuthStateChanged
is a function with callbackInstead, replace the implement of onAuthStateChanged
by this:
onAuthStateChanged: jest.fn(cb => cb({ name: 'Shaun' }));
Upvotes: 3