#Firebase jest test issue

13 messages · Page 1 of 1 (latest)

valid osprey
#

trying to test my SIGN IN component using jest & react library test , but every time when i run the SIGN IN test i encounter firebase auth issue saying that my api-key is wrong , while the app working perfectly , is there anyway that i can neglect the firebase from testing , or how to test the firebase functional and useAuth , i'm new to test

limpid forge
#

So I am not sure how you have your tests set up, but I do believe firebase has a test suite for auth to use in testing that mocks out auth. But I think it is only used to verify rules, you may need mock out initializeApp and pass it to getAuth. For what I'm reading, this seems to be the way of it. Here is a something for github issues (scroll to the bottom for the short explanation): https://github.com/firebase/firebase-js-sdk/issues/2940

And here is a solution on stackoverflow that may be used in your case: https://stackoverflow.com/questions/72194253/firebase-error-auth-invalid-api-key-with-demo-project

They provide those tests to mock auth states and other things so that there are no network requests being made and that unwanted updates to production data don't occur.

cloud coral
#

@valid osprey which one Vite or normal react ?

valid osprey
#

Vite

cloud coral
#

use VITE_APP_

#

VITE_APP

valid osprey
#

You mean for process.env for env variables ??

cloud coral
#

right

#

apiKey: ${import.meta.env.VITE_APP_API_KEY}

#

@valid osprey

valid osprey
#

There’s no issue with the env variables , the app works perfectly , but the issue when test keep yalling for not reason — (I think the problem related to jest testing behaviour ) @cloud coral

cloud coral
valid osprey