Created
May 16, 2015 19:36
-
-
Save bradgignac/9bd566bb40c5a60b343c to your computer and use it in GitHub Desktop.
React + Sizzle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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