Last active
September 23, 2023 19:23
-
-
Save YonatanKra/ec1e22a734679edb0cbc92de5c1b65b3 to your computer and use it in GitHub Desktop.
Tauri-demo: fire user state event only on successful login
This file contains 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
it('should emit `user-status-change` event when login successful', async () => { | |
const firebaseAuth = await import('firebase/auth'); | |
(firebaseAuth.signInWithEmailAndPassword as any).mockImplementation(async () => { | |
(firebaseAuth.getAuth as any).mockReturnValue({ | |
currentUser: { | |
uid: '123', | |
email: 'test@test.com' | |
} | |
}); | |
}); | |
const spy = vi.fn(); | |
auth.addEventListener('user-status-change', spy); | |
await auth.login('email', 'password'); | |
const eventCallsWithSuccessfulLogin = spy.mock.calls.length; | |
expect(eventCallsWithSuccessfulLogin).toBe(1); | |
}); | |
it('should prevent emit of event `user-status-change` when login unsuccessful', async () => { | |
const firebaseAuth = await import('firebase/auth'); | |
(firebaseAuth.signInWithEmailAndPassword as any).mockImplementation(async () => { | |
(firebaseAuth.getAuth as any).mockReturnValue({ | |
currentUser: null | |
}); | |
}); | |
const spy = vi.fn(); | |
auth.addEventListener('user-status-change', spy); | |
await auth.login('email', 'password'); | |
const eventCallsWithUnsuccessfulLogin = spy.mock.calls.length; | |
expect(eventCallsWithUnsuccessfulLogin).toBe(0); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment