Skip to content

Commit

Permalink
Failing test for memory leak issue #954
Browse files Browse the repository at this point in the history
renderComponentToString registers events. If the calling code
does not unmount the component or unregister the listeners
this will leak memory. Passing this test should fix this.
  • Loading branch information
Glenn Murray committed Jan 24, 2014
1 parent 0af9c3e commit d422ebd
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/environment/__tests__/ReactServerRendering-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ require('mock-modules')
.dontMock('ReactMount')
.dontMock('ReactServerRendering')
.dontMock('ReactTestUtils')
.dontMock('ReactMarkupChecksum');
.dontMock('ReactMarkupChecksum')
.dontMock('EventPluginHub');

var mocks = require('mocks');

Expand All @@ -37,6 +38,7 @@ var ReactTestUtils;
var ReactServerRendering;
var ReactMarkupChecksum;
var ExecutionEnvironment;
var EventPluginHub;

var ID_ATTRIBUTE_NAME;

Expand All @@ -50,6 +52,7 @@ describe('ReactServerRendering', function() {
ExecutionEnvironment.canUseDOM = false;
ReactServerRendering = require('ReactServerRendering');
ReactMarkupChecksum = require('ReactMarkupChecksum');
EventPluginHub = require('EventPluginHub');

var DOMProperty = require('DOMProperty');
ID_ATTRIBUTE_NAME = DOMProperty.ID_ATTRIBUTE_NAME;
Expand Down Expand Up @@ -234,6 +237,20 @@ describe('ReactServerRendering', function() {
expect(numClicks).toEqual(1);
});

it('should not register listeners', function() {
var Link = React.createClass({
handleClick: function() {},
render: function() {
return <a onClick={this.handleClick}>link</a>;
}
});
var link = <Link />;
ReactServerRendering.renderComponentToString(link, function(str) {
var listener = EventPluginHub.getListener(link._rootNodeID, 'onClick');
expect(listener).not.toEqual(link.handleClick);
});
});

it('should throw with silly args', function() {
expect(
ReactServerRendering.renderComponentToString.bind(
Expand Down

0 comments on commit d422ebd

Please sign in to comment.