Skip to content

Commit b4ea6ef

Browse files
Edit ref test
1 parent ef70d41 commit b4ea6ef

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

packages/react-core/src/components/TextArea/__tests__/TextArea.test.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ test('Renders disabled text area using disabled', () => {
5757
expect(screen.getByRole('textbox')).toBeDisabled();
5858
});
5959

60-
test('Renders read only text area using isReadOnly', () => {
61-
render(<TextArea aria-label="is read only textarea" isReadOnly />);
60+
test('Renders read only text area using readOnlyVariant', () => {
61+
render(<TextArea aria-label="is read only textarea" readOnlyVariant={'default'} />);
6262
expect(screen.getByRole('textbox')).toHaveAttribute('readonly');
6363
});
6464

@@ -116,10 +116,17 @@ test('Does not throw console error when aria-label is given but no id', () => {
116116
expect(console.error).not.toHaveBeenCalled();
117117
});
118118

119+
test('TextArea can be accessed via passed ref', () => {
120+
const testRef: React.RefObject<HTMLTextAreaElement> = React.createRef();
121+
render(<TextArea ref={testRef} />);
122+
global.scrollTo = jest.fn();
123+
testRef.current?.focus();
124+
expect(screen.getByRole('textbox')).toHaveFocus();
125+
});
126+
119127
test('Matches the snapshot', () => {
120128
const { asFragment } = render(
121129
<TextArea className="custom class" isRequired isDisabled autoResize aria-label="test textarea" />
122130
);
123-
124131
expect(asFragment()).toMatchSnapshot();
125132
});

0 commit comments

Comments
 (0)