How to mock react-navigation properly with jest?

Viewed 711

I get the following during npm test:

console.warn node_modules/react-navigation/src/react-navigation.js:23
      `createNavigationContainer()` has been deprecated, please use `createAppContainer()` instead. You can also import createAppContainer directly from @react-navigation/native
console.warn node_modules/react-navigation/src/react-navigation.js:161
      Importing the stack Transitioner directly from react-navigation is now deprecated. Instead, import { Transitioner } from "react-navigation-stack";

This appeared after mocking the navigation module, here it is my __mocks__/react-navigation.tsx file:

import React from "react";
import { SafeAreaViewProps } from "react-navigation";

jest.mock("react-navigation", () => ({
  ...require.requireActual("react-navigation"),
  NavigationEvents: "mockNavigationEvents",
  withNavigation: (Component: React.ComponentClass) => (props: any) => (
    <Component navigation={{ navigate: jest.fn() }} {...props} />
  ),
  SafeAreaView: ({ children }: SafeAreaViewProps) => <>{children}</>,
  ThemeColors: {
    light: {
      label: "rgba(0, 0, 0, 0.9)",
      bodyContent: "",
    },
    dark: {
      body: "rgba(0, 0, 0, 0.9)",
      bodyContent: "",
    },
  },
}));
module.exports = require.requireMock("react-navigation");

What do I do wrong? Could you help, please?

React-Navigation version: 3.11.0

0 Answers
Related