Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest Test - The current environment does not support the specified persistence type

I use jest to run some test on my Create React App with Firebase Web SDK coupled with FirebaseUI

Whenever I try to run some tests with --env=jsdom - I run into : The current environment does not support the specified persistence type. seems related to Auth

Are there any known related issue/workaround ? the code seems to work/compile properly aside from the tests.

Google didn't help much

Here is the test, pretty basic. HAd to add import "firebase/storage"; because of this : firebase.storage() is not a function in jest test cases

Thanks in advance

import React from "react";

import Enzyme from "enzyme";
import Adapter from "enzyme-adapter-react-16";
import "firebase/storage";
import {filterIngredientsToRemove} from "./shoppingList-reducer";

Enzyme.configure({adapter: new Adapter()});

describe("", () => {
    let shoppingList;
    let recipeId;

    beforeEach(() => {
        shoppingList = {
            shoppingListItems: {
                "1234": {ingredientId: 987, name: "patate", recipeId: 1234},
                "2345": {ingredientId: 987, name: "patate", recipeId: 5432}
            },
            shoppingListRecipes: {
                "1234": {portion: 3}
            }
        };

        recipeId = 1234;
    });

    it("should filter out the shoppinglistItems with the provided recipeId", () => {
        const result = filterIngredientsToRemove(recipeId, shoppingList.shoppingListItems);
        expect(result).toEqual([{ingredientId: 987, name: "patate", recipeId: 1234}]);
    });
});
like image 853
Matthieu Veillon Avatar asked Dec 08 '18 00:12

Matthieu Veillon


1 Answers

Are you setting persistence in your firebase config? Persistence is not supported in the test environment, so you can do something like this to circumvent it:

firebase.auth().setPersistence(process.env.NODE_ENV === 'test' 
  ? firebase.auth.Auth.Persistence.NONE 
  : firebase.auth.Auth.Persistence.LOCAL);
like image 149
Pete Tyldesley Avatar answered Sep 20 '22 12:09

Pete Tyldesley