shoelace/src/components/option/option.test.ts

45 wiersze
1.5 KiB
TypeScript
Czysty Zwykły widok Historia

2023-01-13 20:43:55 +00:00
import { aTimeout, expect, fixture, html, waitUntil } from '@open-wc/testing';
2022-12-20 18:36:53 +00:00
import sinon from 'sinon';
import type SlOption from './option';
2022-12-17 16:27:30 +00:00
describe('<sl-option>', () => {
2022-12-20 18:36:53 +00:00
it('passes accessibility test', async () => {
const el = await fixture<SlOption>(html`
<sl-select label="Select one">
2022-12-28 21:07:37 +00:00
<sl-option value="1">Option 1</sl-option>
<sl-option value="2">Option 2</sl-option>
<sl-option value="3">Option 3</sl-option>
<sl-option value="4" disabled>Disabled</sl-option>
2022-12-20 18:36:53 +00:00
</sl-select>
`);
await expect(el).to.be.accessible();
});
it('default properties', async () => {
const el = await fixture<SlOption>(html` <sl-option>Test</sl-option> `);
expect(el.value).to.equal('');
expect(el.disabled).to.be.false;
expect(el.getAttribute('aria-disabled')).to.equal('false');
});
it('changes aria attributes', async () => {
const el = await fixture<SlOption>(html` <sl-option>Test</sl-option> `);
el.disabled = true;
await aTimeout(100);
expect(el.getAttribute('aria-disabled')).to.equal('true');
});
2022-12-28 20:31:42 +00:00
it('emits the slotchange event when the label changes', async () => {
const el = await fixture<SlOption>(html` <sl-option>Text</sl-option> `);
const slotChangeHandler = sinon.spy();
2022-12-17 16:27:30 +00:00
2022-12-28 20:31:42 +00:00
el.addEventListener('slotchange', slotChangeHandler);
2022-12-20 18:36:53 +00:00
el.textContent = 'New Text';
2022-12-28 20:31:42 +00:00
await waitUntil(() => slotChangeHandler.calledOnce);
expect(slotChangeHandler).to.have.been.calledOnce;
2022-12-17 16:27:30 +00:00
});
});