Skip to content

Commit

Permalink
Test the clock
Browse files Browse the repository at this point in the history
  • Loading branch information
mj12albert committed Mar 13, 2024
1 parent 3133bf6 commit ec6d6de
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
import { createRenderer, screen, fireEvent } from '@mui/internal-test-utils';
import { unstable_useNumberInput as useNumberInput } from '@mui/base/unstable_useNumberInput';

describe('useNumberInput2', () => {
const { clock, render } = createRenderer();

describe('press and hold', () => {
clock.withFakeTimers();

it('should call onChange continuously', () => {
const handleChange = spy();
function NumberInput(props: { defaultValue: number }) {
const { getInputProps, getIncrementButtonProps } = useNumberInput({
...props,
onChange: handleChange,
});

return (
<div role="group">
<button {...getIncrementButtonProps()} data-testid="incrementBtn" />
<input data-testid="test-input" {...getInputProps()} />
</div>
);
}
render(<NumberInput defaultValue={0} />);

const incrementBtn = screen.getByTestId('incrementBtn');

fireEvent.mouseDown(incrementBtn);

clock.tick(100);
clock.tick(100);
clock.runToLast();

expect(handleChange.callCount).to.equal(3);
});
});
});

0 comments on commit ec6d6de

Please sign in to comment.