Created
September 20, 2023 04:58
-
-
Save YonatanKra/029c69c4204c03072ac380ecb818820d to your computer and use it in GitHub Desktop.
Tauri-demo: listen to login attempt event specification
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 evoke the login function from Auth on `login-attempt` event', () => { | |
isLoggedIn = false; | |
app.connectedCallback(); | |
const email = 'ff@gmail.com'; | |
const password = '123456'; | |
const loginComponent = app.shadowRoot?.querySelector('yag-login'); | |
const spy = vi.spyOn(authComponent, 'login'); | |
loginComponent!.dispatchEvent(new CustomEvent('login-attempt', {detail: {email, password}})); | |
expect(spy).toHaveBeenCalledWith(email, password); | |
}); | |
it('should remove `login-attempt` listener to the old loginComponent', () => { | |
isLoggedIn = false; | |
app.connectedCallback(); | |
const oldLoginComponent = app.shadowRoot?.querySelector('yag-login') as HTMLElement; | |
const removeEventListenerSpy = vi.spyOn(oldLoginComponent, 'removeEventListener'); | |
isLoggedIn = true; | |
authComponent.dispatchEvent(new CustomEvent('user-status-change')); | |
expect(removeEventListenerSpy).toHaveBeenCalledWith('login-attempt', expect.any(Function)); | |
removeEventListenerSpy.mockRestore(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment