Skip to content

Commit

Permalink
chore: [capricorn86#1410] Add two tests around labels wrapping inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
Lanny committed Apr 17, 2024
1 parent c29f36c commit 81b88b8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/jest-environment/test/jquery/JQuery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ describe('JQuery', () => {
<b>Bold</b>
<!-- Comment 2 !-->
</article>
<label id="checkbox-label">
<input type="checkbox" />
<span>Label</span>
</label>
`;
});

Expand All @@ -25,4 +29,11 @@ describe('JQuery', () => {
JQuery('span').addClass('test-span');
expect(document.body.children[0].children[1].getAttribute('class')).toBe('test-span');
});

it('Handles clicks on labels correctly', () => {
const onClick = jest.fn();
JQuery('#checkbox-label input').on('click', onClick);
JQuery('#checkbox-label')[0].click();
expect(onClick).toHaveBeenCalledTimes(1);
});
});
14 changes: 14 additions & 0 deletions packages/jest-environment/test/react/React.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,18 @@ describe('React', () => {
await TESTING_LIBRARY_USER.click(button);
expect(document.querySelector('p span').textContent).toBe('test');
});

it('handles clicks on labels correctly', async () => {
const onClick = jest.fn();
const { getByTestId } = ReactTestingLibrary.render(
<label data-testid="checkbox-label">
<input type="checkbox" onClick={onClick} />
<span>Label</span>
</label>
);

await TESTING_LIBRARY_USER.click(getByTestId('checkbox-label'));

expect(onClick).toHaveReturnedTimes(1);
});
});

0 comments on commit 81b88b8

Please sign in to comment.