Last active
September 30, 2023 04:32
-
-
Save YonatanKra/f50d6bdf30fb75b937f9abc69993f0e8 to your computer and use it in GitHub Desktop.
Tauri-demo: refactor login and signup mocks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setUserCreds(firebaseAuth: any, successful: boolean, user = { | |
uid: '123', | |
email: '[email protected]' | |
}) { | |
return async () => { | |
(firebaseAuth.getAuth as any).mockReturnValue({ | |
currentUser: successful ? user : null | |
}); | |
if (successful) firebaseAuth.authChangeCallback(); | |
return { | |
user | |
}; | |
} | |
} | |
function setLogin(firebaseAuth: any, successful: boolean) { | |
(firebaseAuth.signInWithEmailAndPassword as any).mockImplementation(setUserCreds(firebaseAuth, successful)); | |
} | |
function setSignUp(firebaseAuth: any, successful: boolean) { | |
(firebaseAuth.createUserWithEmailAndPassword as any).mockImplementation(setUserCreds(firebaseAuth, successful)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment