Skip to content

Commit

Permalink
test(TextInput): update tests to include falsy values
Browse files Browse the repository at this point in the history
  • Loading branch information
dominiccarrington committed Oct 22, 2024
1 parent 9c16b52 commit b448b59
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/components/TextInput/TextInput.unit.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,35 @@ describe('<TextInput/>', () => {
expect(textInputComponent.props()['aria-describedby']).toBe(undefined);
});

it('should have the clear input button displayed when not disabled', async () => {
it('should not have the clear input button displayed when value is empty', async () => {
const textInputComponent = (
await mountAndWait(<TextInput aria-label="text-input" value="Hello World" />)
).find(TextInput);

expect(textInputComponent.find('.clear-icon').exists()).toBe(true);
});

it('should not have the clear input button displayed when isDisabled', async () => {
const textInputComponent = (
await mountAndWait(<TextInput aria-label="text-input" value="Hello World" isDisabled />)
await mountAndWait(<TextInput aria-label="text-input" value="" />)
).find(TextInput);

expect(textInputComponent.find('.clear-icon').exists()).toBe(false);
});

it.each(['hello world', '0', '123', ' '])(
'should have the clear input button displayed when not disabled (value = "%s")',
async (value) => {
const textInputComponent = (
await mountAndWait(<TextInput aria-label="text-input" value={value} />)
).find(TextInput);

expect(textInputComponent.find('.clear-icon').exists()).toBe(true);
}
);

it.each(['', 'hello world', '0', '123', ' '])(
'should not have the clear input button displayed when isDisabled (value = "%s")',
async (value) => {
const textInputComponent = (
await mountAndWait(<TextInput aria-label="text-input" value={value} isDisabled />)
).find(TextInput);

expect(textInputComponent.find('.clear-icon').exists()).toBe(false);
}
);
});

describe('actions', () => {
Expand Down

0 comments on commit b448b59

Please sign in to comment.