Created
September 20, 2023 06:33
-
-
Save YonatanKra/faf10f1aafae39f29a62b157c43aebe8 to your computer and use it in GitHub Desktop.
Tauri-demo: the auth component
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
import { Auth } from './auth'; | |
describe('login', () => { | |
let auth: Auth; | |
beforeAll(() => { | |
customElements.define('yag-auth', Auth); | |
}); | |
beforeEach(() => { | |
auth = document.createElement('yag-auth') as Auth; | |
}); | |
describe('init', () => { | |
it('should exist', () => { | |
expect(auth).toBeTruthy(); | |
expect(auth.isLoggedIn()).toBe(false); | |
}); | |
}); | |
describe('login', () => { | |
it('should toggle `isLoggedIn`', () => { | |
auth.login(); | |
expect(auth.isLoggedIn()).toBe(true); | |
}); | |
it('shuold emit `user-status-change` event', () => { | |
const spy = vi.fn(); | |
auth.addEventListener('user-status-change', spy); | |
auth.login(); | |
expect(spy).toHaveBeenCalled(); | |
}); | |
}); | |
}); |
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
export class Auth extends HTMLElement { | |
#isLoggedIn = false; | |
isLoggedIn() { | |
return this.#isLoggedIn; | |
} | |
login() { | |
this.#isLoggedIn = true; | |
this.dispatchEvent(new CustomEvent('user-status-change')); | |
} | |
constructor() { | |
super(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment