Skip to content

Instantly share code, notes, and snippets.

@asbjornenge
Last active August 29, 2015 14:05
Show Gist options
  • Save asbjornenge/2779930743a8000c6dab to your computer and use it in GitHub Desktop.
Save asbjornenge/2779930743a8000c6dab to your computer and use it in GitHub Desktop.
React test utils wrapper
var React = require('react')
var ReactAddons = require('react/addons')
var ReactTestUtils = React.addons.TestUtils
var reactTestQueryUtil = function (tree) {
this.tree = tree
}
reactTestQueryUtil.prototype.class = function (cls) {
this.class = cls
return this
}
reactTestQueryUtil.prototype.one = function () {
if (this.class) return ReactTestUtils.findRenderedDOMComponentWithClass(this.tree, this.class)
}
reactTestQueryUtil.prototype.all = function () {
if (this.class) return ReactTestUtils.scryRenderedDOMComponentsWithClass(this.tree, this.class)
}
module.exports = function(tree) { return new reactTestQueryUtil(tree) }
@asbjornenge
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment