Skip to content

Commit

Permalink
test(formfield): add test for multiple error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinWijnant committed Dec 19, 2020
1 parent 34ec4c4 commit 803eae7
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/components/FormField/FormField.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ describe('FormField', () => {
expect(queryByText(/Something went wrong/)).not.toBe(null);
});

test('undefined errorMessage should not be rendered', () => {
const { queryByText } = render(
<FormField errorMessage={undefined}>Form elements here</FormField>,
);
expect(queryByText(/undefined/)).toBe(null);
});

test('array of error messages should all be rendered', () => {
const { queryByText } = render(
<FormField errorMessage={['A first error', 'A second error', undefined]}>
Form elements here
</FormField>,
);
expect(queryByText(/A second error/)).not.toBe(null);
expect(queryByText(/A first error/)).not.toBe(null);
expect(queryByText(/undefined/)).toBe(null);
});

test('hint should be rendered', () => {
const { queryByText } = render(
<FormField hint={<span>You should look here</span>}>Form elements here</FormField>,
Expand Down

0 comments on commit 803eae7

Please sign in to comment.