Created
September 16, 2023 13:27
-
-
Save YonatanKra/744deb6c8b33ada60dbf26497207ca8a to your computer and use it in GitHub Desktop.
Tauri-demo: add yag-app with yag-greet to main
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 { App } from './app'; | |
| customElements.define('yag-app', App); | |
| describe('app', () => { | |
| let app: App; | |
| beforeEach(() => { | |
| app = document.createElement('yag-app') as App; | |
| document.body.appendChild(app); | |
| }); | |
| afterEach(() => { | |
| app.remove(); | |
| }); | |
| it('should be have an open shadow root', () => { | |
| expect(app.shadowRoot?.mode).toBe('open'); | |
| }); | |
| it('should set yag-greeter inside the shadow root', () => { | |
| expect(app.shadowRoot?.querySelector('yag-greeter')).toBeTruthy(); | |
| }); | |
| }); |
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 const template = ` | |
| <yag-greeter></yag-greeter> | |
| `; | |
| const templateElement = document.createElement('template'); | |
| templateElement.innerHTML = template; | |
| export class App extends HTMLElement{ | |
| constructor(){ | |
| super(); | |
| this.attachShadow({mode: 'open'}); | |
| const templateHTML = templateElement.content.cloneNode(true); | |
| this.shadowRoot?.appendChild(templateHTML); | |
| } | |
| } |
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
| describe('main', () => { | |
| it ('should define yag-greeter', () => { | |
| expect(customElements.get('yag-greeter')).toBeDefined(); | |
| }); | |
| it ('should define yag-app', () => { | |
| expect(customElements.get('yag-app')).toBeDefined(); | |
| }); | |
| it('should set yag-app inside the body', () => { | |
| expect(document.body.innerHTML).toBe('<yag-app></yag-app>'); | |
| }); | |
| }); |
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 { App } from "./components/app"; | |
| import { Greeter } from "./components/greeter"; | |
| customElements.define("yag-app", App); | |
| customElements.define("yag-greeter", Greeter); | |
| document.body.innerHTML = "<yag-app></yag-app>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment