What is identity-obj-proxy?
The identity-obj-proxy package is primarily used for mocking module exports in JavaScript tests. It's especially useful when working with CSS Modules in a Jest testing environment, as it allows you to proxy the imported CSS Modules with an identity object that returns the module's name for any property access. This way, tests can be run without having to worry about the actual CSS and focus on the JavaScript logic.
Mocking CSS Modules in Jest
This code snippet demonstrates how to mock a CSS module import using identity-obj-proxy in a Jest test. It replaces the actual styles with an object that has the same keys as the class names defined in the CSS file, but with values equal to the keys themselves.
jest.mock('styles.module.css', () => require('identity-obj-proxy'));