Testing Select Component Multiple Selection Behavior in Preact
This test suite validates the functionality of the Select component in Preact’s compatibility layer, focusing on multiple selection behavior and value handling. It ensures proper rendering and state management of select elements with multiple options.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
preactjs/preact
compat/test/browser/select.test.js
import { setupScratch, teardown } from '../../../test/_util/helpers';
import React, { createElement, render } from 'preact/compat';
describe('Select', () => {
let scratch;
beforeEach(() => {
scratch = setupScratch();
});
afterEach(() => {
teardown(scratch);
});
it('should work with multiple selected (array of values)', () => {
function App() {
return (
<select multiple value={['B', 'C']}>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
);
}
render(<App />, scratch);
const options = scratch.firstChild.children;
expect(options[0]).to.have.property('selected', false);
expect(options[1]).to.have.property('selected', true);
expect(options[2]).to.have.property('selected', true);
expect(scratch.firstChild.value).to.equal('B');
});
});