Skip to content

Instantly share code, notes, and snippets.

@marr
Created May 21, 2015 21:40
Show Gist options
  • Save marr/afbf41b138102e951af1 to your computer and use it in GitHub Desktop.
Save marr/afbf41b138102e951af1 to your computer and use it in GitHub Desktop.
TestUtils.renderLightbox = function(dispatcher, lightboxDefn, opt_location, callback) {
var Foo = React.createClass({
getChildContext: function() {
return { dispatcher: dispatcher };
},
childContextTypes: {
dispatcher: React.PropTypes.object.isRequired
},
render: function() {
var transitions = lightboxDefn.transitions || {};
return React.createElement(LightboxHandler,
{ nextTransition: transitions.next,
prevTransition: transitions.prev,
elem: lightboxDefn.element,
elemProps: lightboxDefn.props });
}
});
var cb, location;
if (typeof opt_location === 'string') {
location = new TestLocation([opt_location]);
cb = callback;
} else {
location = new TestLocation(['/']);
cb = arguments[2];
}
var routes = (
<Router.Route name="default" handler={Foo} path="/" />
);
var root;
Router.run(routes, location, function(Handler, state) {
var root = TestUtils.renderIntoDocument(<Handler {...state} />);
cb && cb(root, location);
});
return root;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment