Skip to content

Commit

Permalink
Test onClick is registered on TextField root
Browse files Browse the repository at this point in the history
  • Loading branch information
mj12albert committed Aug 17, 2023
1 parent 5c3b57c commit 2faaf69
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/mui-material/src/TextField/TextField.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ describe('<TextField />', () => {
});
});

describe('click handling', () => {
describe('event: click', () => {
it('should trigger `onClick` only once', () => {
const handleClick = spy();
const { getByRole } = render(
Expand All @@ -237,5 +237,25 @@ describe('<TextField />', () => {
fireEvent.click(getByRole('textbox'));
expect(handleClick.callCount).to.equal(1);
});

it('registers `onClick` on the root slot', () => {
const handleRootClick = spy();
const handleInputClick = spy();
const { getByTestId } = render(
<TextField
data-testid="root"
onClick={handleRootClick}
inputProps={{
onClick: handleInputClick,
}}
/>,
);

const root = getByTestId('root');

fireEvent.click(root);
expect(handleRootClick.callCount).to.equal(1);
expect(handleInputClick.callCount).to.equal(0);
});
});
});

0 comments on commit 2faaf69

Please sign in to comment.