Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

update checkbox test

kruzhambus3906b756cd74
diff --git a/src/ui/test/Checkbox.test.tsx b/src/ui/test/Checkbox.test.tsx
index ed7f6d7ae..4297e61db 100644
--- a/src/ui/test/Checkbox.test.tsx
+++ b/src/ui/test/Checkbox.test.tsx
@@ -1,11 +1,10 @@
/* eslint-disable testing-library/prefer-screen-queries */
/* eslint-disable import/no-extraneous-dependencies */
import React from 'react'
-import { render } from '@testing-library/react'
+import { render, fireEvent } from '@testing-library/react'
import Checkbox from '../Checkbox'
describe('Checkbox', () => {
- // do not use getByRole
test('renders a checkbox', () => {
const { getByText } = render(<Checkbox label='Checkbox' checked />)
expect(getByText('Checkbox')).toBeInTheDocument()
@@ -17,4 +16,13 @@ describe('Checkbox', () => {
)
expect(getByRole('checkbox')).toHaveAttribute('id', 'custom-id')
})
+
+ test('clicking the checkbox calls the onChange handler', () => {
+ const onChange = jest.fn()
+ const { getByRole } = render(
+ <Checkbox label='Checkbox' checked onChange={onChange} />,
+ )
+ fireEvent.click(getByRole('checkbox'))
+ expect(onChange).toHaveBeenCalled()
+ })
})