Skip to content

Instantly share code, notes, and snippets.

@YonatanKra
Last active September 23, 2023 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YonatanKra/ec1e22a734679edb0cbc92de5c1b65b3 to your computer and use it in GitHub Desktop.
Save YonatanKra/ec1e22a734679edb0cbc92de5c1b65b3 to your computer and use it in GitHub Desktop.
Tauri-demo: fire user state event only on successful login
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