diff --git a/src/select/index.test.tsx b/src/select/index.test.tsx new file mode 100644 index 0000000..f9814ed --- /dev/null +++ b/src/select/index.test.tsx @@ -0,0 +1,42 @@ +import { Formik } from 'formik' +import React from 'react' +import { Form } from '../form' +import Select from './index' +import '@testing-library/jest-dom/extend-expect' +import { act } from 'react-dom/test-utils' +import { fireEvent, render } from '@testing-library/react' + +const TestSelect = () => { + return ( + { + }}> +
+ +
+
+ ) +} + +test('renders select', async () => { + const { queryByRole } = render() + expect(queryByRole('combobox')).toBeInTheDocument() +}) + +test('sets initial value', async () => { + const { queryByText } = render() + expect(queryByText('Zero')).toBeInTheDocument() +}) + +test('changes selected upon clicking', async () => { + const { getByRole, queryByText, getByText, getAllByText } = render() + const selector = getByRole('combobox') + expect(queryByText('Zero')).toBeInTheDocument() + fireEvent.mouseDown(selector) + await act(async () => { + fireEvent.click(getByText('One')) + }) + expect(getAllByText('One').length).toBeGreaterThan(1) +})