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

Passing props while using React Native Testing and TypeScript

$
0
0

Hey I am trying to implement the react-native-testing-library for a project which is also using TypeScript. My question involves the best way to pass props to my tests.

For example if my src/example.tsx is:

import React from 'react';import { Button, View } from 'react-native';export interface Props {    text: string;    func: () => void;}export const Example: React.FC<Props> = ({ text, func }: Props) => {    return (<View><Button onPress={func} title={text} /></View>    )}

And my src/test/example.test.tsx is:

import React from 'react';import { render } from '@testing-library/react-native';import { Example, Props } from '../example';describe('example', () => {    const { getAllBy } = render(<Example {...Props} />); <---- *Error}

I obviously get the error:

'Props' only refers to a type, but is being used as a value here.

What is the best way to do this. Do I need to manually create a mock props object to feed into each of my components or is there a better way to do this?


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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