Accepted answer

It's happening because in your test environment you're not initiate the firebase app (using initializeApp) and you probably shouldn't (you don't want to communicate with firebase every time you run a test, especially not unit tests). This kind question also applies to other external services like your own server and external APIs.

So how can you test your app?

The answer is mocking - supply an alternative implementations for those services to the tests environment. There are some kind of mocking, depends on what and how you want to mock. Also, sometimes, the tools supply their own testkit (which, again, supply a testable implementation for the methods it expose).

In this case, you can use jest mocking mechanizm to mock the response from firebase so your app "doesn't know" it received the data from other resource, and will act like it should.

The relevant jest methods are spyOn and mockImplementation, and here is an example (I simplified your component):


test("mount", async () => {
  const fetchPromise = Promise.resolve([{ name: "order1" }]);
  jest.spyOn(firebase, "app").mockImplementation(() => ({
    firestore: () => ({
      collection: () => ({
        get: () => fetchPromise
  let wrapper = mount(<App />);
  await fetchPromise;


export default class App extends React.Component {
  state = {
    orders: []

  fetchOrders() {
    try {
        .then((snapShot) => {
          this.setState({ orders: snapShot });
    } catch {
      console.log("do nothing");

  componentDidMount() {

  render() {
    return (
      <div className="App">
        { => (
          <span key={}>{}</span>
} (Click on the Tests tab)

Related Query

More Query from same tag