My limited number of tests seem to suggest that the answer is no. I'm writing a unit test for a parent level React component (aka a controller view) that has a dependency on a store. However, Jest is not providing an auto-mock for the store, as the documentation suggests it should, and is instead calling the real implementation.
Is this a bug or by design? If the latter, is the takeaway that unit testing react components is not desirable?
Edit 1
Automocking works just fine when testing a CommonJs module; it's just not working for react components.
Automocking can be a useful technique when writing unit tests for your React components, especially when you want to isolate your component from its dependencies, like stores, and test the component in isolation.
Jest should automatically mock CommonJS modules using its automocking feature. However, it may not always work for modules that export non-CJS types, such as ES modules. Additionally, Jest might not work as expected if you are using Webpack aliases, module loaders, or other similar features.
If Jest is not providing an auto-mock for your store, there may be a few reasons for this. For example, the store might not be defined as a CommonJS module, or there may be an issue with Jest's automocking feature.
One way to ensure that your store is mocked correctly is to manually mock the store module in your test file by creating a mock store that implements the necessary methods and properties used by your component. This way, you can control the behavior of the store and simulate different scenarios to test your component's behavior.
Another approach is to use a library like redux-mock-store to create a mock store that you can use in your tests. This library provides an implementation of the Redux store that you can use to simulate state changes and dispatch actions to test your component's behavior.
In general, unit testing React components is desirable and can help you catch bugs early in the development cycle. While Jest's automocking feature can be helpful, it is not always reliable, and you may need to manually mock your dependencies to ensure that your tests are accurate and repeatable.