jeudi 14 juin 2018

How to unit test react-native-firebase?

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

Aucun commentaire:

Enregistrer un commentaire