Jest Test - 当前环境不支持指定的持久性类型

问题描述 投票:4回答:1

我使用jest在Firebase Web SDK和FirebaseUI的Create React App上运行一些测试

每当我尝试用--env = jsdom运行一些测试时 - 我遇到:The current environment does not support the specified persistence type.似乎与Auth有关

是否有任何已知的相关问题/解决方法?除了测试之外,代码似乎可以正常工作/编译。

谷歌没有多大帮助

这是测试,非常基础。 HAd因为这个而添加import "firebase/storage";firebase.storage() is not a function in jest test cases

提前致谢

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}]);
    });
});
firebase jestjs firebaseui
1个回答
0
投票

你在firebase配置中设置持久性吗?测试环境不支持持久性,因此您可以执行以下操作来规避持久性:

firebase.auth().setPersistence(process.env.NODE_ENV === 'test' 
  ? firebase.auth.Auth.Persistence.NONE 
  : firebase.auth.Auth.Persistence.LOCAL);
© www.soinside.com 2019 - 2024. All rights reserved.