https://github.com/keyz/identity-obj-proxy
An identity object using ES6 proxies. Useful for mocking webpack imports like CSS Modules.
https://github.com/keyz/identity-obj-proxy
Last synced: over 1 year ago
JSON representation
An identity object using ES6 proxies. Useful for mocking webpack imports like CSS Modules.
- Host: GitHub
- URL: https://github.com/keyz/identity-obj-proxy
- Owner: keyz
- License: mit
- Created: 2015-12-24T12:37:59.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2022-01-29T03:32:40.000Z (over 4 years ago)
- Last Synced: 2025-03-29T18:08:39.305Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 11.7 KB
- Stars: 503
- Watchers: 3
- Forks: 18
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# identity-obj-proxy [](https://travis-ci.org/keyanzhang/identity-obj-proxy) [](https://www.npmjs.com/package/identity-obj-proxy) [](https://coveralls.io/github/keyanzhang/identity-obj-proxy?branch=master)
An identity object using ES6 proxies. Useful for mocking webpack imports. For instance, you can tell Jest to mock this object as imported [CSS modules](https://github.com/css-modules/css-modules); then all your `className` lookups on the imported `styles` object will be returned as-is.
```
npm install identity-obj-proxy
```
## ~~Real world example~~ Wait what does that even mean
### tl;dr
For a React component like
```js
import React, { Component } from 'react';
import styles from './App.css'; // CSS Modules here
export default class App extends Component {
render() {
return (
Hello, world!
);
}
}
```
we can generate a snapshot as below (notice that the class names get correctly mocked):
```js
exports[`test App renders correctly 1`] = `
Hello, world!
`;
```
For more information, please take a look at https://github.com/keyanzhang/jest-css-modules-example/ and https://jestjs.io/docs/en/webpack.html.
## Requirement
No flag is required for Node.js `v6.*`; use `node --harmony_proxies` flag for `v5.*` and `v4.*`.
## Example
``` javascript
import idObj from 'identity-obj-proxy';
console.log(idObj.foo); // 'foo'
console.log(idObj.bar); // 'bar'
console.log(idObj[1]); // '1'
```