|
| 1 | +import {Window} from '../index.ts'; |
| 2 | + |
| 3 | +import {describe, it, expect, beforeEach} from 'vitest'; |
| 4 | + |
| 5 | +describe('innerHtml', () => { |
| 6 | + beforeEach(() => { |
| 7 | + const window = new Window(); |
| 8 | + Window.setGlobalThis(window); |
| 9 | + }); |
| 10 | + |
| 11 | + it('parses a simple element', () => { |
| 12 | + const element = document.createElement('div'); |
| 13 | + element.innerHTML = '<ui-button>Press me!</ui-button>'; |
| 14 | + |
| 15 | + const button = element.querySelector('ui-button'); |
| 16 | + expect(button?.textContent).toBe('Press me!'); |
| 17 | + }); |
| 18 | + |
| 19 | + it('parses an element with attributes', () => { |
| 20 | + const element = document.createElement('div'); |
| 21 | + element.innerHTML = '<ui-button data-id="123">Press me!</ui-button>'; |
| 22 | + |
| 23 | + const button = element.querySelector('ui-button'); |
| 24 | + expect(button?.textContent).toBe('Press me!'); |
| 25 | + expect(button?.getAttribute('data-id')).toBe('123'); |
| 26 | + }); |
| 27 | + |
| 28 | + it('parses an element with attributes on newlines', () => { |
| 29 | + const element = document.createElement('div'); |
| 30 | + element.innerHTML = `<ui-button |
| 31 | + data-id="123" |
| 32 | + data-id2="456" |
| 33 | + data-id3="789" |
| 34 | + data-id4="multiline |
| 35 | +content |
| 36 | +works too" |
| 37 | +variant="primary" tone="neutral" |
| 38 | + >Press me!</ui-button>`; |
| 39 | + |
| 40 | + const button = element.querySelector('ui-button'); |
| 41 | + |
| 42 | + expect(button?.getAttribute('data-id')).toBe('123'); |
| 43 | + expect(button?.getAttribute('data-id2')).toBe('456'); |
| 44 | + expect(button?.getAttribute('data-id3')).toBe('789'); |
| 45 | + expect(button?.getAttribute('data-id4')).toBe( |
| 46 | + 'multiline\ncontent\nworks too', |
| 47 | + ); |
| 48 | + expect(button?.getAttribute('variant')).toBe('primary'); |
| 49 | + expect(button?.getAttribute('tone')).toBe('neutral'); |
| 50 | + }); |
| 51 | +}); |
0 commit comments