question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

jest-expo cause an error with Firebase SDK 7.5.1 or later

See original GitHub issue

🐛 Bug Report

Summary of Issue

The following jest test case works fine with Firebase SDK 7.5.0 or earlier but cause an error with Firebase SDK 7.5.1 or later.

https://github.com/goodpic/expo-jest-firebase/blob/master/src/__tests__/firebase.spec.ts

 PASS  src/__tests__/firebase.spec.ts
  UseProduct
    ✓ fetchProduct (157 ms)

  console.log
    Error: addEventListener and attachEvent are unavailable.
        at goog.events.listen_ (/Users/junkaneko/workspace/expo-jest-firebase/node_modules/@firebase/node_modules/google-closure-library/closure/goog/events/events.js:280:15)
        at goog.events.listen (/Users/junkaneko/workspace/expo-jest-firebase/node_modules/@firebase/node_modules/google-closure-library/closure/goog/events/events.js:189:12)
        at ak.addStorageListener [as $] (/Users/junkaneko/workspace/expo-jest-firebase/node_modules/@firebase/auth/dist/src/storage/localstorage.js:172:5)
        at pk.addListener (/Users/junkaneko/workspace/expo-jest-firebase/node_modules/@firebase/auth/dist/src/authstorage.js:459:3)
        at new Am (/Users/junkaneko/workspace/expo-jest-firebase/node_modules/@firebase/auth/dist/src/storageusermanager.js:107:3)
        at new Km (/Users/junkaneko/workspace/expo-jest-firebase/node_modules/@firebase/auth/dist/src/auth.js:121:7)
        at Object.instanceFactory (/Users/junkaneko/workspace/expo-jest-firebase/node_modules/@firebase/auth/dist/src/exports_auth.js:679:16)
        at Provider.getOrInitializeService (/Users/junkaneko/workspace/expo-jest-firebase/node_modules/@firebase/component/src/provider.ts:187:33)
        at Provider.getImmediate (/Users/junkaneko/workspace/expo-jest-firebase/node_modules/@firebase/component/src/provider.ts:95:29)
        at FirebaseAppImpl._getService (/Users/junkaneko/workspace/expo-jest-firebase/node_modules/@firebase/app/src/firebaseApp.ts:127:54)

      at src/__tests__/firebase.spec.ts:16:15

Workaround

remove “preset”: “jest-expo” from jest.config.js

https://github.com/goodpic/expo-jest-firebase/commit/2dadd693bef1b37ac9221c5985803d9250a4ebde#r41011908

Environment - output of expo diagnostics & the platform(s) you’re targeting

Expo CLI 3.22.3 environment info:
    System:
      OS: macOS 10.15.5
      Shell: 5.7.1 - /bin/zsh
    Binaries:
      Node: 12.18.3 - ~/.nvm/versions/node/v12.18.3/bin/node
      npm: 6.14.6 - ~/.nvm/versions/node/v12.18.3/bin/npm
    IDEs:
      Xcode: 11.6/11E708 - /usr/bin/xcodebuild
    npmPackages:
      expo: ~38.0.8 => 38.0.8
      react: ~16.11.0 => 16.11.0
      react-dom: ~16.11.0 => 16.11.0
      react-native: https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz => 0.62.2
      react-native-web: ~0.11.7 => 0.11.7
    npmGlobalPackages:
      expo-cli: 3.22.3

Reproducible Demo

Steps to Reproduce

git clone https://github.com/goodpic/expo-jest-firebase.git

Place the firebase config file under /config/firebase.ts

const projectId = 'YOUR_PROJECT_ID'
export const firebaseConfig = {
  projectId,
  apiKey: YOUR_API_KEY,
  authDomain: `${projectId}.firebaseapp.com`,
  databaseURL: `https://${projectId}.firebaseio.com`,
  storageBucket: `${projectId}.appspot.com`,
}

then run jest

npm install
npm run test

Expected Behavior vs Actual Behavior

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
tickietackiecommented, Nov 11, 2020

@goodpic I also cannot get this to work. But I am using the packages “firebase-tools” and “firebase”. Do you know if there is a combination of versions which work? I get the same error message and just want a working configuration.

Nvm, I just found out mocking them to do nothing works for me:

window.addEventListener = jest.fn(); window.attachEvent= jest.fn();

1reaction
brentvatnecommented, Jul 29, 2020

@goodpic - we can’t really search out compatibility issues with different versions of arbitrary libraries, but if you investigate and give us more info on precisely what’s wrong (eg: no mock for xyz api, where we should mock out addEventListener) we can definitely help with that

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuration issue while setting up jest expo - #3 by teja ...
Please provide the following: SDK Version: 39 Platforms(Android/iOS/web/all): all This is the package.json for the expo project: { "main": ...
Read more >
How To Integrate Firebase Authentication With an Expo App
In this tutorial, let's take a look at how as a mobile developer building applications using Expo SDK, you can integrate and use...
Read more >
Select data from firebase via id gives me a CORS error
(Tl;dr: Try adding '.json' to the end of the endpoint.) I would recommend reading this page to get a general understanding of what...
Read more >
react-native-scrollable-tab-view | iOS library
I have changed to PropTypes to "prop-types" but still get Error evaluating ... iOS app getting stuck at launch screen after importing firebase...
Read more >
Integrating Firebase authentication into an Expo mobile app
It's time to set up the Firebase SDK. For that, we'll add the Firebase setup code provided above into our application.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found