Skip to content

Instantly share code, notes, and snippets.

@YonatanKra
Created September 20, 2023 06:33
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/faf10f1aafae39f29a62b157c43aebe8 to your computer and use it in GitHub Desktop.
Save YonatanKra/faf10f1aafae39f29a62b157c43aebe8 to your computer and use it in GitHub Desktop.
Tauri-demo: the auth component
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();
});
});
});
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