Skip to content

Commit e131357

Browse files
committed
Merge pull request #5394 from spicyj/tu-shallow-ref
Revert #4993 with an added test for refs
2 parents 578312e + 9419976 commit e131357

File tree

2 files changed

+9
-37
lines changed

2 files changed

+9
-37
lines changed

src/test/ReactTestUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ ReactShallowRenderer.prototype.render = function(element, context) {
431431
context = emptyObject;
432432
}
433433
var transaction = ReactUpdates.ReactReconcileTransaction.getPooled(true);
434-
transaction.perform(this._render, this, element, transaction, context);
434+
this._render(element, transaction, context);
435435
ReactUpdates.ReactReconcileTransaction.release(transaction);
436436
};
437437

src/test/__tests__/ReactTestUtils-test.js

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -87,59 +87,31 @@ describe('ReactTestUtils', function() {
8787
expect(componentWillUnmount).toBeCalled();
8888
});
8989

90-
it('should run all lifecycle methods', function() {
91-
var componentWillMount = jest.genMockFn();
92-
var componentDidMount = jest.genMockFn();
93-
var componentWillReceiveProps = jest.genMockFn();
94-
var shouldComponentUpdate = jest.genMockFn();
95-
var componentWillUpdate = jest.genMockFn();
96-
var componentDidUpdate = jest.genMockFn();
97-
var componentWillUnmount = jest.genMockFn();
98-
90+
it('can shallow render to null', function() {
9991
var SomeComponent = React.createClass({
10092
render: function() {
101-
return <SomeComponent onChange={() => this.setState({a: 1})} />;
102-
},
103-
componentWillMount,
104-
componentDidMount,
105-
componentWillReceiveProps,
106-
shouldComponentUpdate() {
107-
shouldComponentUpdate();
108-
return true;
93+
return null;
10994
},
110-
componentWillUpdate,
111-
componentDidUpdate,
112-
componentWillUnmount,
11395
});
11496

11597
var shallowRenderer = ReactTestUtils.createRenderer();
11698
shallowRenderer.render(<SomeComponent />);
117-
shallowRenderer.getRenderOutput().props.onChange();
118-
shallowRenderer.render(<SomeComponent />);
119-
shallowRenderer.unmount();
12099

121-
expect(componentWillMount).toBeCalled();
122-
expect(componentDidMount).toBeCalled();
123-
expect(componentWillReceiveProps).toBeCalled();
124-
expect(shouldComponentUpdate).toBeCalled();
125-
expect(componentWillUpdate).toBeCalled();
126-
expect(componentDidUpdate).toBeCalled();
127-
expect(componentWillUnmount).toBeCalled();
100+
var result = shallowRenderer.getRenderOutput();
101+
102+
expect(result).toBe(null);
128103
});
129104

130-
it('can shallow render to null', function() {
105+
it('can shallow render with a ref', function() {
131106
var SomeComponent = React.createClass({
132107
render: function() {
133-
return null;
108+
return <div ref="hello" />;
134109
},
135110
});
136111

137112
var shallowRenderer = ReactTestUtils.createRenderer();
113+
// Shouldn't crash.
138114
shallowRenderer.render(<SomeComponent />);
139-
140-
var result = shallowRenderer.getRenderOutput();
141-
142-
expect(result).toBe(null);
143115
});
144116

145117
it('lets you update shallowly rendered components', function() {

0 commit comments

Comments
 (0)