Skip to content

Commit

Permalink
test(clerk-js): User regex when finding elements by text
Browse files Browse the repository at this point in the history
  • Loading branch information
octoper committed Dec 22, 2023
1 parent 903be7d commit d08015a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
18 changes: 9 additions & 9 deletions packages/clerk-js/src/ui/elements/__tests__/PlainInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ describe('PlainInput', () => {
});

const { getByLabelText, queryByText } = render(<Field isRequired />, { 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();
});

Expand All @@ -90,8 +90,8 @@ describe('PlainInput', () => {
});

const { getByLabelText, getByText } = render(<Field isOptional />, { 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();
});

Expand Down Expand Up @@ -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');
});
Expand All @@ -154,7 +154,7 @@ describe('PlainInput', () => {

const { findByLabelText, findByText } = render(<Field actionLabel={'take action'} />, { 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();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -174,7 +174,7 @@ describe('RadioGroup', () => {

const { findByLabelText, findByText } = render(<Field />, { 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();
});
});

0 comments on commit d08015a

Please sign in to comment.