Created
December 2, 2015 15:09
-
-
Save squeedee/66c38beca9f0531eba3f to your computer and use it in GitHub Desktop.
Real rendering in jasmine with react
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
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