Skip to content

Instantly share code, notes, and snippets.

@dmatteo
Last active September 15, 2016 09:21
Show Gist options
  • Save dmatteo/e082e5866761b737855c to your computer and use it in GitHub Desktop.
Save dmatteo/e082e5866761b737855c to your computer and use it in GitHub Desktop.
Testing a React.js component with `jsdomify` and `mocha`
import expect from 'unexpected';
import jsdomify from 'jsdomify';
describe('MyComponent', () => {
let React, TestUtils, getInstance, MyComponent;
before(() => {
jsdomify.create();
React = require('react/addons');
TestUtils = React.addons.TestUtils;
MyComponent = require('./MyComponent');
getInstance = (props = {}) => {
return TestUtils.renderIntoDocument(
<MyComponent {...props} />
);
};
});
after(() => {
jsdomify.destroy();
});
it('should render', () => {
const instance = getInstance();
expect(instance, 'to be defined');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment