React native 测试套件运行失败,找不到模块'@环境';从'';mylocalfile.js“;

React native 测试套件运行失败,找不到模块'@环境';从'';mylocalfile.js“;,react-native,jestjs,environment-variables,dotenv,React Native,Jestjs,Environment Variables,Dotenv,我正在我的项目中使用jest单元测试。它在一段时间内运行良好。我最近已经将dotenv与我的项目集成在一起。现在所有文件的测试都失败了。执行运行测试时收到以下错误 项目dotenv结构 .env在我的根文件夹中 我的根文件夹/src/typings中的env.d.ts 我的实际代码 import { Linking, AsyncStorage, Platform, Alert } from "react-native"; import { Toast } from &quo

我正在我的项目中使用jest单元测试。它在一段时间内运行良好。我最近已经将dotenv与我的项目集成在一起。现在所有文件的测试都失败了。执行运行测试时收到以下错误

项目dotenv结构

  • .env在我的根文件夹中
  • 我的根文件夹/src/typings中的env.d.ts
  • 我的实际代码

    import { Linking, AsyncStorage, Platform, Alert } from "react-native";
    import { Toast } from "native-base";
    import { ZOOM_APP_PLAYSTORE, ZOOM_APP_APPSTORE, ZOOM_URL } from "@env";
    import { General } from "../Constants";
    
    当我运行应用程序时,它工作正常,并且只运行一个测试

    单元测试-jest

    测试代码

    describe("Testpage Component", () => {
        it('renders without crashing', () => {
            const rendered = renderer.create(<Provider store={store}>
                <DrawerComponent />
            </Provider>).toJSON();
            expect(rendered).toBeTruthy();
        });
    });
    
    description(“测试页面组件”),()=>{
    它('渲染而不崩溃',()=>{
    const rendered=renderer.create(
    ).toJSON();
    expect(rendered.toBeTruthy();
    });
    });
    
    嘿,您找到解决此问题的方法了吗?我目前面临着同样的问题。这个问题是因为@env library配置文件,所以我已经完全删除了它,并在这里使用了react native config而不是react native dotenv的maintainer!这很可能是由于不正确的babel配置造成的。你的babel配置是什么?嘿,你找到解决这个问题的方法了吗?我目前面临着同样的问题。这个问题是因为@env library配置文件,所以我已经完全删除了它,并在这里使用了react native config而不是react native dotenv的maintainer!这很可能是由于不正确的babel配置造成的。你的巴别塔配置是什么?