- Notifications
You must be signed in to change notification settings - Fork 49.8k
Closed
Description
We need a way to test the output of a single level React component without resolving it all the way down to the bottom layer (whatever that is).
I'm thinking something like this:
var shallowRenderer = ReactTestUtils.createRenderer(); shallowRenderer.render(<SomeComponent />); shallowRenderer.attachRef('myRefName', someMock); var result = shallowRenderer.getRenderOutput(); expect(result.type).toBe('div'); expect(result.props.children).toEqual([ <span className="child1" />, <span className="child2" /> ]); shallowRenderer.render(<SomeComponent aNew="Prop" />); var updatedResult = shallowRenderer.getRenderOutput(); expect(updatedResult.type).toBe('a'); updatedResult.props.onClick(mockEvent); var updatedResultCausedByClick = shallowRenderer.getRenderOutput(); expect(updatedResult.props.className).toBe('was-clicked'); var instance = shallowRenderer.getMountedInstance(); instance.customFunction(); var updatedResultCausedByCustomFunction = shallowRenderer.getRenderOutput(); expect(updatedResultCausedByCustomFunction.props.className).toBe('custom');Basically, this fix needs to go through the entire life-cycle of ReactCompositeComponent. It just needs to bail out whenever it would've continued rendering.
Metadata
Metadata
Assignees
Labels
No labels