Это мой текущий макет, я хочу, чтобы createUserWithEmailAndPassword
вернул firebase.auth.UserCredential
, чтобы я мог проверить, вызывается ли он в моем App.ts
App.spe c. ts
import myAuthenticationPlugin from 'authenticationPlugin/App'
import firebase from 'firebase/app'
jest.mock('firebase/app', () => {
return {
auth: jest.fn().mockReturnThis(),
currentUser: {
email: 'test',
uid: '123',
emailVerified: true
},
signInWithEmailAndPassword: jest.fn(),
createUserWithEmailAndPassword:jest.fn(() => {
return {
user:{
sendEmailVerification:jest.fn(),
},
}
}),
initializeApp:jest.fn()
};
});
describe('Test for signup (email,password)',() => {
it('createUserWithEmailAndPassword ()',async () => { //this works
await myAuthenticationPlugin.signup(email, password)
expect(firebase.auth().createUserWithEmailAndPassword).toBeCalledWith(email, password)
})
it('sendEmailVerification()',async ()=>{
await myAuthenticationPlugin.signup(email, password)
const userCredential= await firebase.auth().createUserWithEmailAndPassword(email,password)
if(userCredential.user!=null){
expect(userCredential.user.sendEmailVerification).toBeCalled() //this fails as i'm not able to mock properly
}
})
})
Приложения
import firebase from 'firebase/app'
import 'firebase/auth'
import './Init'
const App= {
signup: async (email, password) => {
const userCredential = await firebase.auth().createUserWithEmailAndPassword(email, password)
await userCredential.user.sendEmailVerification()
return `Check your email for verification mail before logging in`
},
}
export default App