Skip to content

Instantly share code, notes, and snippets.

@bradgignac
Created May 16, 2015 19:36
Show Gist options
  • Save bradgignac/9bd566bb40c5a60b343c to your computer and use it in GitHub Desktop.
Save bradgignac/9bd566bb40c5a60b343c to your computer and use it in GitHub Desktop.
React + Sizzle
let sizzle = require('sizzle');
let React = require('react/addons');
let TestUtils = React.addons.TestUtils;
global.findAll = function (root, selector) {
return TestUtils.findAllInRenderedTree(root, function (component) {
let node = React.findDOMNode(component)
return sizzle.matchesSelector(node, selector);
});
};
global.find = function (root, selector) {
let matches = findAll(root, selector);
if (matches.length != 1) {
throw Error(`Did not find exactly one match (found: ${matches.length}) for selector:${selector}`);
}
return matches[0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment