Skip to content

Instantly share code, notes, and snippets.

@asbjornenge
Last active August 29, 2015 14:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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

Obviously missing a lot, but you get the "gist" :bowtie:

var _component = util(_tree).class('myReactComponent').one()

@asbjornenge
Copy link
Author

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