import { expect } from 'chai'; import sinon from 'sinon'; import React from 'react'; import ReactDOM from 'react-dom'; import TestUtils from 'react-addons-test-utils'; import MyComponent from './MyComponent'; /* * Pattern to be used for testing instance methods of components. These should not be used to test impementation details. * Examples of good applications of this pattern: * - Testing interactions with a stateful DOM API (eg. iframe). NOTE: components should not interact with DOM APIs * that are not related to visual display. * - Test interactions with an external UI library (eg. an image editor like Aviary) */ describe('MyComponent', () => { const getComponent = (props = {}) => { props = Object.assign({ onChange: sinon.spy(), }, props); const node = document.createElement('div'); // Notice the different rendering method here const component = ReactDOM.render( ), node); return Object.assign(props, { component }); }; describe('myMethod', () => { it('returns some value', () => { const { component } = getComponent(); expect(component.myMethod()).to.equal('some value'); }); }); });