Skip to content

Commit 655e299

Browse files
committed
Add test
1 parent 2cf5223 commit 655e299

File tree

1 file changed

+42
-18
lines changed

1 file changed

+42
-18
lines changed

packages/react/src/slider/root/SliderRoot.test.tsx

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,26 +2005,50 @@ describe.skipIf(typeof Touch === 'undefined')('<Slider.Root />', () => {
20052005
expect(root).not.to.have.attribute('data-focused');
20062006
});
20072007

2008-
it('prop: validate', async () => {
2009-
await render(
2010-
<Field.Root validate={() => 'error'}>
2011-
<Slider.Root>
2012-
<Slider.Control>
2013-
<Slider.Thumb data-testid="thumb" />
2014-
</Slider.Control>
2015-
</Slider.Root>
2016-
<Field.Error data-testid="error" />
2017-
</Field.Root>,
2018-
);
2008+
describe('prop: validate', async () => {
2009+
it('runs on blur by default', async () => {
2010+
await render(
2011+
<Field.Root validate={() => 'error'}>
2012+
<Slider.Root>
2013+
<Slider.Control>
2014+
<Slider.Thumb data-testid="thumb" />
2015+
</Slider.Control>
2016+
</Slider.Root>
2017+
<Field.Error data-testid="error" />
2018+
</Field.Root>,
2019+
);
20192020

2020-
const input = screen.getByRole('slider');
2021-
expect(input).not.to.have.attribute('aria-invalid');
2021+
const input = screen.getByRole('slider');
2022+
expect(input).not.to.have.attribute('aria-invalid');
20222023

2023-
const thumb = screen.getByTestId('thumb');
2024-
fireEvent.focus(thumb);
2025-
fireEvent.blur(thumb);
2026-
await flushMicrotasks();
2027-
expect(input).to.have.attribute('aria-invalid', 'true');
2024+
const thumb = screen.getByTestId('thumb');
2025+
fireEvent.focus(thumb);
2026+
fireEvent.blur(thumb);
2027+
await flushMicrotasks();
2028+
expect(input).to.have.attribute('aria-invalid', 'true');
2029+
});
2030+
2031+
it('receives an array value for range sliders', async () => {
2032+
const validateSpy = spy();
2033+
await render(
2034+
<Field.Root validate={validateSpy}>
2035+
<Slider.Root defaultValue={[5, 12]}>
2036+
<Slider.Control>
2037+
<Slider.Thumb data-testid="thumb" />
2038+
<Slider.Thumb />
2039+
</Slider.Control>
2040+
</Slider.Root>
2041+
<Field.Error data-testid="error" />
2042+
</Field.Root>,
2043+
);
2044+
2045+
const thumb = screen.getByTestId('thumb');
2046+
fireEvent.focus(thumb);
2047+
fireEvent.blur(thumb);
2048+
await flushMicrotasks();
2049+
expect(validateSpy.callCount).to.equal(1);
2050+
expect(validateSpy.args[0][0]).to.deep.equal([5, 12]);
2051+
});
20282052
});
20292053

20302054
it('prop: validationMode=onChange', async () => {

0 commit comments

Comments
 (0)