Home / Companies / Bit / Blog / Post Details
Content Deep Dive

Sharing renderer context with envs and test

Blog post from Bit

Post Details
Company
Bit
Date Published
Author
Ashan Fernando
Word Count
313
Language
English
Hacker News Points
-
Summary

Compositions, also known as component previews, are renderings of a component in various variations and often require a common context such as a theme provider, router, or auth provider. To streamline the process, a common render context can be created for both compositions and unit tests, facilitating their integration and reducing redundancy. This can be achieved by creating a React Context component and adding it as a wrapper to the environment mounter preview and the react-testing-library render function for unit tests. To further simplify the process and avoid repetitive code, a custom testing library can be developed by extending the react-testing-library function to automatically include the render context component as a wrapper. This approach enhances the ease of implementing and maintaining consistent testing and preview setups across projects.