From 82802a0da9c6be7ab1f6fb58e8422f6ae2f7b13a Mon Sep 17 00:00:00 2001 From: Michele Bertoli Date: Fri, 11 Nov 2016 15:34:11 +0000 Subject: [PATCH] Make the Shallow Rendering example clearer (#8269) * Make the Shallow Rendering example clearer I was reading through the documentation, and I found that the `render` call on the `renderer` was missing. * Use a regular function to define MyComponent --- docs/addons-test-utils.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/docs/addons-test-utils.md b/docs/addons-test-utils.md index ddd3a340..7f4d251e 100644 --- a/docs/addons-test-utils.md +++ b/docs/addons-test-utils.md @@ -53,20 +53,26 @@ Call [`createRenderer()`](#createrenderer) in your tests to create a shallow ren After `shallowRenderer.render()` has been called, you can use [`shallowRenderer.getRenderOutput()`](#shallowrenderer.getrenderoutput) to get the shallowly rendered output. -You can then begin to assert facts about the output. For example, if your component's render method returns: +You can then begin to assert facts about the output. For example, if you have the following component: ```javascript -
- Title - -
+function MyComponent() { + return ( +
+ Title + +
+ ); +} ``` Then you can assert: ```javascript const renderer = ReactTestUtils.createRenderer(); -result = renderer.getRenderOutput(); +renderer.render(); +const result = renderer.getRenderOutput(); + expect(result.type).toBe('div'); expect(result.props.children).toEqual([ Title,