Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

How can I add a testId attribute to a React Native component for Testing Library when TypeScript prevents me?

$
0
0

I'm writing a React Native components using TypeScript and testing them with React Native Testing Library.

I want to put a testId attribute on a React Native component like so:

<TextInput testId="foo" />

And then refer to it in a test like so:

it('receives a search string', () => {  const { getByTestId } = render(<FooComponent />);;  const textBox = getByTestId("foo");  fireEvent.changeText(textBox,"some fake text");  expect(textBox.value).toEqual("some fake text");});

But TypeScript won't allow me to put a testId attribute on a component.

How do I get TypeScript to recognize the added attributes like testId from @testing-library/react-native.


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>