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:
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
const setOptions = (navigation: any, route: any) => { }
I get:
Type '(navigation: any, route: any) => void' is not assignable to type '(options: Partial<NativeStackNavigationOptions>) => void'.
const setOptions = (props: HomeProps) => { }
I get:
Type '(props: HomeProps) => void' is not assignable to type '(options: Partial<NativeStackNavigationOptions>) => void'.
How can I solve this?