小编Rob*_*ins的帖子

如何从 @react-native-firebase/auth 模拟身份验证

我试图从 npm 库 @react-native-firebase/auth 模拟 auth 模块,但是,我不断收到此错误。我尝试在下面嘲笑它,但显然它一定是不正确的,我只是不确定什么是不正确的。

TypeError: Cannot read property 'credential' of undefined
Run Code Online (Sandbox Code Playgroud)
jest.mock('@react-native-firebase/auth', () => ({
  auth: {
    GoogleAuthProvider: {
      credential: jest.fn().mockReturnValue('123'),
    },
  },
}));

jest.mock('@react-native-community/google-signin', () => ({
  GoogleSignin: {
    signIn: jest.fn().mockReturnValue('123'),
  },
}));
Run Code Online (Sandbox Code Playgroud)
    import auth from '@react-native-firebase/auth';
    import {GoogleSignin} from '@react-native-community/google-signin';
    
    export const GoogleLogin = async function (): Promise<void | string> {
      // Get the users ID token
      const {idToken} = await GoogleSignin.signIn();
    
      // Create a Google credential with the token
      const googleCredential = auth.GoogleAuthProvider.credential(idToken);
    
      try …
Run Code Online (Sandbox Code Playgroud)

unit-testing firebase reactjs jestjs react-native

2
推荐指数
1
解决办法
2233
查看次数

标签 统计

firebase ×1

jestjs ×1

react-native ×1

reactjs ×1

unit-testing ×1