Last active
September 17, 2023 09:05
-
-
Save YonatanKra/f88c4e918f9dbe5d1e76bfd0fbb415ac to your computer and use it in GitHub Desktop.
Tauri-demo: Test remove listener in disconnectedCallback
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
| it('should remove `user-status-change` listener to the old authComponent', () => { | |
| const addEventListenerSpy = vi.spyOn(HTMLElement.prototype, 'addEventListener'); | |
| app.connectedCallback(); | |
| const oldAuthComponent = authComponent; | |
| const removeEventListenerSpy = vi.spyOn(oldAuthComponent, 'removeEventListener'); | |
| app.disconnectedCallback(); | |
| app.connectedCallback(); | |
| expect(addEventListenerSpy).toHaveBeenCalledWith('user-status-change', expect.any(Function)); | |
| expect(removeEventListenerSpy).toHaveBeenCalledWith('user-status-change', expect.any(Function)); | |
| expect(removeEventListenerSpy.mock.calls[0][1]).toBe(addEventListenerSpy.mock.calls[0][1]); | |
| addEventListenerSpy.mockRestore(); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment