I'm trying to write unit tests for a react spa web application that uses micro-frontend architecture. My first step is to write unit tests for the application container.
The application container react component uses a react-router containing a switch with subsequent routes to render the components in the main content area.
Each application is mounted to the application container using JavaScript runtime integration.
I'm using React-Testing-Library and Jest as part of my testing toolset.
I've searched high and low across the Internet and haven't found any useful articles on the issues I'm having. Most of them show a demo of testing a web application that doesn't relate to my scenario.
I have 3 problems that I would like some guidance on.
Since Micro Frontends are composed of multiple layers of components chained together with authentication and other business logic. Should I be testing the "page components" only? Or should I be testing the entire application container starting from the App component? If neither is true, how should I be testing this application?
I tried to test on the page component level to avoid authentication issues and for simplicity sake, but the component contains a component from React Router library, and Jest is complaining that I should not be using
<Link>
component that isn't enclosed within a<Router>
component. However, the<Router>
component is present at the parent component level when executed in runtime. How can I tell Jest to "ignore" this problem?I could not find a configuration that allows me to ignore this error.
Due to issue #2, I tried to write unit tests by rendering the
<App>
component, but this component is passed into a Higher Order Component that performs authentication validation. How can I focus on testing the end result instead of the functionality of the authentication HOC just so I can get the component to render and for my tests to execute?