node package manager

react-test-utilities

react-test-utilities

Testing utilities for react.

npm install --save-dev react-test-utilities

renderAndFind(Component)

Renders a component into dom and returns that node.

var dom = renderAndFind(<Component/>);
expect(dom.text).toBe('Hello World.');

stubRouterContext(Component, props, stubs)

Stubs react-router's this.router.context so you can test components that rely on it.

import someReactRouterDependantComponent from 'components/someReactRouterDependantComponent';
 
var Subject = stubRouterContext(someReactRouterDependantComponent); 
var dom = renderAndFind(<Subject/>);
expect(someAssertion).toBe(true);