Testing Custom Built-in Element Integration in Preact
This test suite evaluates the integration of customized built-in elements within Preact components. It verifies proper creation, rendering, and lifecycle behavior of custom elements that extend native HTML elements, ensuring compatibility between Preact’s virtual DOM and the Web Components specification.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
preactjs/preact
test/browser/customBuiltInElements.test.js
import { createElement, render, Component } from 'preact';
import { setupScratch, teardown } from '../_util/helpers';
/** @jsx createElement */
const runSuite = typeof customElements == 'undefined' ? xdescribe : describe;
runSuite('customised built-in elements', () => {
let scratch;
beforeEach(() => {
scratch = setupScratch();
});
afterEach(() => {
teardown(scratch);
});
it('should create built in elements correctly', () => {
class Foo extends Component {
render() {
return <div is="built-in" />;
}
}
const spy = sinon.spy();
class BuiltIn extends HTMLDivElement {
connectedCallback() {
spy();
}
}
customElements.define('built-in', BuiltIn, { extends: 'div' });
render(<Foo />, scratch);
expect(spy).to.have.been.calledOnce;
});
});