Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
identity-obj-proxy
Advanced tools
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'));
proxyquire is a package that allows you to override dependencies during testing. It is similar to identity-obj-proxy in that it helps with mocking modules, but it is more general-purpose and can be used to proxy any module, not just CSS modules. It provides more control over the mocking behavior compared to identity-obj-proxy.
An identity object using ES6 proxies. Useful for testing trivial webpack imports. For instance, you can tell Jest to mock this object as imported CSS modules; then all your className
lookups on the imported styles
object will be returned as-is.
npm install identity-obj-proxy
No flag is required for Node.js v6.*
; use node --harmony_proxies
flag for v5.*
and v4.*
.
import idObj from 'identity-obj-proxy';
console.log(idObj.foo); // 'foo'
console.log(idObj.bar); // 'bar'
console.log(idObj[1]); // '1'
FAQs
an identity object using ES6 proxies
We found that identity-obj-proxy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.