From d08015ace5046b4ae71efda46bf678758089042c Mon Sep 17 00:00:00 2001 From: Vaggelis Yfantis Date: Fri, 22 Dec 2023 22:53:07 +0200 Subject: [PATCH] test(clerk-js): User regex when finding elements by text --- .../ui/elements/__tests__/PlainInput.test.tsx | 18 +++++++++--------- .../ui/elements/__tests__/RadioGroup.test.tsx | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/clerk-js/src/ui/elements/__tests__/PlainInput.test.tsx b/packages/clerk-js/src/ui/elements/__tests__/PlainInput.test.tsx index 394f04f8dd..219e4867d3 100644 --- a/packages/clerk-js/src/ui/elements/__tests__/PlainInput.test.tsx +++ b/packages/clerk-js/src/ui/elements/__tests__/PlainInput.test.tsx @@ -75,9 +75,9 @@ describe('PlainInput', () => { }); const { getByLabelText, queryByText } = render(, { wrapper }); - expect(getByLabelText('some label')).toHaveValue('init value'); - expect(getByLabelText('some label')).toHaveAttribute('required'); - expect(getByLabelText('some label')).toHaveAttribute('aria-required', 'true'); + expect(getByLabelText(/some label/i)).toHaveValue('init value'); + expect(getByLabelText(/some label/i)).toHaveAttribute('required'); + expect(getByLabelText(/some label/i)).toHaveAttribute('aria-required', 'true'); expect(queryByText(/optional/i)).not.toBeInTheDocument(); }); @@ -90,8 +90,8 @@ describe('PlainInput', () => { }); const { getByLabelText, getByText } = render(, { wrapper }); - expect(getByLabelText('some label')).not.toHaveAttribute('required'); - expect(getByLabelText('some label')).toHaveAttribute('aria-required', 'false'); + expect(getByLabelText(/some label/i)).not.toHaveAttribute('required'); + expect(getByLabelText(/some label/i)).toHaveAttribute('aria-required', 'false'); expect(getByText(/optional/i)).toBeInTheDocument(); }); @@ -136,9 +136,9 @@ describe('PlainInput', () => { await userEvent.click(getByRole('button', { name: /set error/i })); - expect(await findByText('some error')).toBeInTheDocument(); + expect(await findByText(/some error/i)).toBeInTheDocument(); - const label = getByLabelText('some label'); + const label = getByLabelText(/some label/i); expect(label).toHaveAttribute('aria-invalid', 'true'); expect(label).toHaveAttribute('aria-describedby', 'error-firstname'); }); @@ -154,7 +154,7 @@ describe('PlainInput', () => { const { findByLabelText, findByText } = render(, { wrapper }); - fireEvent.focus(await findByLabelText('some label')); - expect(await findByText('some info')).toBeInTheDocument(); + fireEvent.focus(await findByLabelText(/some label/i)); + expect(await findByText(/some info/i)).toBeInTheDocument(); }); }); diff --git a/packages/clerk-js/src/ui/elements/__tests__/RadioGroup.test.tsx b/packages/clerk-js/src/ui/elements/__tests__/RadioGroup.test.tsx index 5c10111e64..70542e45d8 100644 --- a/packages/clerk-js/src/ui/elements/__tests__/RadioGroup.test.tsx +++ b/packages/clerk-js/src/ui/elements/__tests__/RadioGroup.test.tsx @@ -152,7 +152,7 @@ describe('RadioGroup', () => { ); await userEvent.click(getByRole('button', { name: /set error/i })); - expect(await findByText('some error')).toBeInTheDocument(); + expect(await findByText(/some error/i)).toBeInTheDocument(); const radios = getAllByRole('radio'); radios.forEach(radio => { @@ -174,7 +174,7 @@ describe('RadioGroup', () => { const { findByLabelText, findByText } = render(, { wrapper }); - fireEvent.focus(await findByLabelText('One')); - expect(await findByText('some info')).toBeInTheDocument(); + fireEvent.focus(await findByLabelText(/One/i)); + expect(await findByText(/some info/i)).toBeInTheDocument(); }); });