mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
fix(html): prevent tsdown from stripping custom element registrations (#703)
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { safeDefine } from '../safe-define';
|
||||
|
||||
describe('safeDefine', () => {
|
||||
it('registers a custom element', () => {
|
||||
class TestElement extends HTMLElement {
|
||||
static tagName = 'test-sd-register';
|
||||
}
|
||||
|
||||
expect(customElements.get('test-sd-register')).toBeUndefined();
|
||||
safeDefine(TestElement);
|
||||
expect(customElements.get('test-sd-register')).toBe(TestElement);
|
||||
});
|
||||
|
||||
it('does not throw when element is already registered', () => {
|
||||
class TestElement extends HTMLElement {
|
||||
static tagName = 'test-sd-no-throw';
|
||||
}
|
||||
|
||||
customElements.define('test-sd-no-throw', TestElement);
|
||||
expect(() => safeDefine(TestElement)).not.toThrow();
|
||||
});
|
||||
|
||||
it('does not replace an existing registration', () => {
|
||||
class Original extends HTMLElement {
|
||||
static tagName = 'test-sd-no-replace';
|
||||
}
|
||||
class Replacement extends HTMLElement {
|
||||
static tagName = 'test-sd-no-replace';
|
||||
}
|
||||
|
||||
safeDefine(Original);
|
||||
safeDefine(Replacement);
|
||||
expect(customElements.get('test-sd-no-replace')).toBe(Original);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user