Skip to content

Instantly share code, notes, and snippets.

@squeedee
Created December 2, 2015 15:09
Show Gist options
  • Save squeedee/66c38beca9f0531eba3f to your computer and use it in GitHub Desktop.
Save squeedee/66c38beca9f0531eba3f to your computer and use it in GitHub Desktop.
Real rendering in jasmine with react
global.useComponent = function(componentToRender, defaultProperties) {
defaultProperties = _.merge({}, defaultProperties);
beforeEach(function() {
this.renderComponent = function(opts) {
opts = _.assign({}, defaultProperties, opts);
this.component = TestUtils.renderIntoDocument(
React.createElement(componentToRender, opts)
);
// Abusing `any-id` is a variable, dontchaknow.
this.component = React.render(React.createElement(componentToRender, opts), root);
Object.defineProperty(this, '$rendered', {
get: function() { return $(this.component.getDOMNode()); },
set: function() { }
});
};
this.unmountComponent = function() {
if (this.component) {
React.unmountComponentAtNode(this.$rendered.parent()[0]);
delete this.component;
delete this.$rendered;
}
}
});
afterEach(function() {
this.unmountComponent();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment