Skip to content

Instantly share code, notes, and snippets.

@justinobney
Last active December 31, 2015 00:40
Show Gist options
  • Save justinobney/26593cff2b0c8e991198 to your computer and use it in GitHub Desktop.
Save justinobney/26593cff2b0c8e991198 to your computer and use it in GitHub Desktop.
basic react component
{
"presets": [
"es2015",
"stage-2",
"react"
]
}
import React from 'react';
export const MyComponent = ({color}) => {
return (
<div className={`box color-${color}`}></div>
);
};
--compilers js:babel-register
test.js
{
"name": "react-component",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha --opts mocha.opts",
"test:watch": "mocha --opts mocha.opts --watch --reporter min"
},
"author": "Justin Obney",
"license": "MIT",
"devDependencies": {
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-2": "^6.3.13",
"babel-register": "^6.3.13",
"expect": "^1.13.4",
"expect-jsx": "^2.2.1",
"react-addons-test-utils": "^0.14.5"
},
"dependencies": {
"react": "^0.14.5",
"react-dom": "^0.14.5"
}
}
import React from 'react';
import {createRenderer} from 'react-addons-test-utils';
import expect from 'expect';
import expectJSX from 'expect-jsx';
expect.extend(expectJSX);
import { MyComponent } from './index.js';
class TestComponent extends React.Component {}
const render = (component) => {
const renderer = createRenderer();
renderer.render(component);
return renderer.getRenderOutput();
}
describe('expect-jsx', () => {
it('works', () => {
const actualElement = render(<MyComponent color="red" />);
const expectedElement = <div className="box color-red"></div>;
expect(actualElement).toEqualJSX(expectedElement);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment