Skip to content

Instantly share code, notes, and snippets.

@StJohn3D
Created May 19, 2016 15:53
Show Gist options
  • Save StJohn3D/b3ff64146e976eb3fe7758bdc2893677 to your computer and use it in GitHub Desktop.
Save StJohn3D/b3ff64146e976eb3fe7758bdc2893677 to your computer and use it in GitHub Desktop.
Quickly convert react components to jQuery like Cheerio objects for testing - source code from cheerio-react on npm
var ReactDOMServer = require('react-dom/server');
var cheerio = require('cheerio');
module.exports = function( reactClass ) {
var staticMarkup = ReactDOMServer.renderToStaticMarkup(reactClass);
var $ = cheerio.load(staticMarkup);
return $.root().children().first();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment