This repository was archived by the owner on Aug 1, 2020. It is now read-only.
File tree 2 files changed +52
-0
lines changed
website/versioned_docs/version-3.0.0 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -149,6 +149,32 @@ const { unmount } = render(<Login />);
149
149
unmount ();
150
150
```
151
151
152
+ ### asJSON
153
+
154
+ Returns a JSON representation of the current state of your rendered component. This can be useful if
155
+ you need to avoid live bindings and see how your component reacts to events.
156
+
157
+ ``` javascript
158
+ import { render , fireEvent } from ' native-testing-library' ;
159
+
160
+ function TestComponent () {
161
+ const [count , setCount ] = React .useState (0 );
162
+
163
+ return (
164
+ < Button onPress= {() => setCount (state => state + 1 )} title= {` Click to increase: ${ count} ` } / >
165
+ );
166
+ }
167
+
168
+ const { getByText , asJSON } = render (< TestComponent / > );
169
+ const firstRender = asJSON ();
170
+
171
+ fireEvent .press (getByText (/ Click to increase/ ));
172
+
173
+ // This will snapshot the difference before and after the press event.
174
+ // See https://github.com/jest-community/snapshot-diff
175
+ expect (firstRender).toMatchDiffSnapshot (asJSON ());
176
+ ```
177
+
152
178
---
153
179
154
180
## ` cleanup `
Original file line number Diff line number Diff line change @@ -150,6 +150,32 @@ const { unmount } = render(<Login />);
150
150
unmount ();
151
151
```
152
152
153
+ ### asJSON
154
+
155
+ Returns a JSON representation of the current state of your rendered component. This can be useful if
156
+ you need to avoid live bindings and see how your component reacts to events.
157
+
158
+ ``` javascript
159
+ import { render , fireEvent } from ' native-testing-library' ;
160
+
161
+ function TestComponent () {
162
+ const [count , setCount ] = React .useState (0 );
163
+
164
+ return (
165
+ < Button onPress= {() => setCount (state => state + 1 )} title= {` Click to increase: ${ count} ` } / >
166
+ );
167
+ }
168
+
169
+ const { getByText , asJSON } = render (< TestComponent / > );
170
+ const firstRender = asJSON ();
171
+
172
+ fireEvent .press (getByText (/ Click to increase/ ));
173
+
174
+ // This will snapshot the difference before and after the press event.
175
+ // See https://github.com/jest-community/snapshot-diff
176
+ expect (firstRender).toMatchDiffSnapshot (asJSON ());
177
+ ```
178
+
153
179
---
154
180
155
181
## ` cleanup `
You can’t perform that action at this time.
0 commit comments