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: cannot unit test due to error "The current environment does not support the specified persistence type."

See original GitHub issue

[REQUIRED] Describe your environment

  • Operating System version: macOS v10.14.6
  • Browser version: v76.0.3809.132
  • Firebase UI version: v4.2.0
  • Firebase SDK version: v6.6.0

[REQUIRED] Describe the problem

When using Jest to write a test on a component that uses Firebase UI, the test fails due to the error “The current environment does not support the specified persistence type.” This is due to the fact that this library always sets the persistence type to SESSION regardless of the Node environment. However, the test Node environment does not support this type of persistence, and consequently, the persistence should be set to NONE in this case. There does not seem to be a way of overriding this, and potentially no way of writing Jest unit tests for a component that utilizes this library. I believe that this could be handled by simply checking the process.env.NODE_ENV and setting the persistence to NONE if the environment is test, or the library could allow us to pass this in as an optional property.

If I get some time then I may experiment with a couple of approaches, but if a maintainer has an opinion on how to go about this then I am open to suggestions.

Error:

 FAIL  src/auth/containers/login/Login.test.tsx
  ● Login › should render without crashing

    The current environment does not support the specified persistence type.

       5 | 
       6 | describe('Login', () => {
    >  7 |   it('should render without crashing', () => {
         |   ^       8 |     const { unmount } = render(<Login />);
       9 |     unmount();
      10 |   });
      at new Spec (node_modules/jest-jasmine2/build/jasmine/Spec.js:116:22)      at Suite.it (src/auth/containers/login/Login.test.tsx:7:3)
      at Object.describe (src/auth/containers/login/Login.test.tsx:6:1)

  ● Login › should render without crashing

    TypeError: Cannot read property 'delete' of undefined

      at render (node_modules/react-firebaseui/webpack:/StyledFirebaseAuth/src/FirebaseAuth.jsx:116:3)

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
cosminicommented, Jul 28, 2020

My solution was to set persistence and then start the ui. Persistence will check if env is testing and set it to none otherwise it can default to local or session if there’s a remember me option.

Here is a snippet

   firebase
      .auth()
     // can set session if remember me option exists
      .setPersistence(process.env.NODE_ENV === 'test' ? firebase.auth.Auth.Persistence.NONE : firebase.auth.Auth.Persistence.LOCAL)
      .then(function () {
        // get the firebaseui instance
        const ui =
          firebaseui.auth.AuthUI.getInstance() ||
          new firebaseui.auth.AuthUI(firebase.auth())
        ui.start('#firebaseui-auth-container', {/*firebase config here*/})
      })
3reactions
MaxAltenacommented, Mar 28, 2020

Has anyone found a solution or a possible workaround for this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest Test - The current environment does not support the ...
I ran into this issue too. The problem seems to come from the firebaseui constructor, specifically this line ...
Read more >
Using Visual Studio Code to debug Jest based unit tests
The answer is using Visual Studio Code !! You can just place breakpoints, choose whether or not to make a single run, enable...
Read more >
Testing Your Application - Quarkus
So far we have only covered integration style tests that test the app via HTTP endpoints, but what if we want to do...
Read more >
Testing React Native Apps - Jest
If you are upgrading your react-native application and previously used the jest-react-native preset, remove the dependency from your package.
Read more >
Getting started with continuous integration for Nest.js APIs
In this tutorial, I will lead you through building a RESTful API with ... The product.service.spec.ts file will be used to write unit...
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