我试图从 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)