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

Testing React Native app: How to fix: navigation.setOptions is not a function?

$
0
0

Here is the test:

describe('<HomeScreen />', () => {  it('Renders correctly', () => {// const setOptions = jest.fn(); // 1// const setOptions = (navigation: any, route: any) => { } // 2   const setOptions = (props: HomeProps) => { } // 3    render(<Provider store={store}><PersistGate loading={null} persistor={persistor}><HomeScreen navigation={{ setOptions: setOptions }} route={undefined} /></PersistGate></Provider>,    );  });});

I've tried the solutions that are given here and here but they do not work for me.

I think the problem is that I'm using TypeScript and React Navigation v6, because:

  1. const setOptions = jest.fn(); I get:

    Type '{ setOptions: jest.Mock<any, any>; }' is not assignable to type 'NativeStackNavigationProp<RootStackParamList, "Home">'.

    NativeStackNavigationProp<RootStackParamList, "Home"> is the type I have for the component.

    It's this one: export type HomeProps = NativeStackScreenProps<RootStackParamList, 'Home'>;

    Which later I import as HomeProps

  2. const setOptions = (navigation: any, route: any) => { }

    I get:

    Type '(navigation: any, route: any) => void' is not assignable to type '(options: Partial<NativeStackNavigationOptions>) => void'.
  3. const setOptions = (props: HomeProps) => { }

    I get:

    Type '(props: HomeProps) => void' is not assignable to type '(options: Partial<NativeStackNavigationOptions>) => void'.

How can I solve 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>