You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/SnapshotTesting.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ A typical snapshot test case renders a UI component, takes a snapshot, then comp
11
11
12
12
A similar approach can be taken when it comes to testing your React components. Instead of rendering the graphical UI, which would require building the entire app, you can use a test renderer to quickly generate a serializable value for your React tree. Consider this [example test](https://github.com/facebook/jest/blob/master/examples/snapshot/__tests__/link.react.test.js) for a [Link component](https://github.com/facebook/jest/blob/master/examples/snapshot/Link.react.js):
13
13
14
-
```javascript
14
+
```tsx
15
15
importReactfrom'react';
16
16
importrendererfrom'react-test-renderer';
17
17
importLinkfrom'../Link.react';
@@ -51,7 +51,7 @@ It's straightforward to spot when a snapshot test fails after a bug has been int
51
51
52
52
One such situation can arise if we intentionally change the address the Link component in our example is pointing to.
53
53
54
-
```javascript
54
+
```tsx
55
55
// Updated test case with a Link to a different address
Copy file name to clipboardExpand all lines: docs/TutorialReact.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,7 +60,7 @@ module.exports = {
60
60
61
61
Let's create a [snapshot test](SnapshotTesting.md) for a Link component that renders hyperlinks:
62
62
63
-
```javascript
63
+
```tsx
64
64
// Link.react.js
65
65
importReactfrom'react';
66
66
@@ -106,7 +106,7 @@ export default class Link extends React.Component {
106
106
107
107
Now let's use React's test renderer and Jest's snapshot feature to interact with the component and capture the rendered output and create a snapshot file:
108
108
109
-
```javascript
109
+
```tsx
110
110
// Link.react.test.js
111
111
importReactfrom'react';
112
112
importrendererfrom'react-test-renderer';
@@ -196,7 +196,7 @@ React 16 triggers these warnings due to how it checks element types, and the moc
2. Render as a custom element. DOM"custom elements" aren't checked for anything and shouldn't fire warnings. They are lowercase and have a dash in the name.
3. Use `react-test-renderer`. The test renderer doesn't care about element types and will happily accept e.g. `SomeComponent`. You could check snapshots using the test renderer, and check component behavior separately using Enzyme.
@@ -216,7 +216,7 @@ You have to run `yarn add --dev @testing-library/react` to use react-testing-lib
216
216
217
217
Let's implement a checkbox which swaps between two labels:
@@ -281,7 +281,7 @@ You have to run `yarn add --dev enzyme` to use Enzyme. If you are using a React
281
281
282
282
Let's rewrite the test from above using Enzyme instead of react-testing-library. We use Enzyme's [shallow renderer](http://airbnb.io/enzyme/docs/api/shallow.html) in this example.
Copy file name to clipboardExpand all lines: docs/TutorialReactNative.md
+13-8Lines changed: 13 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,13 +12,14 @@ Get a deeper insight into testing a working React Native app example by reading
12
12
Starting from react-native version 0.38, a Jest setup is included by default when running `react-native init`. The following configuration should be automatically added to your package.json file:
13
13
14
14
```json
15
-
// package.json
15
+
{
16
16
"scripts": {
17
17
"test": "jest"
18
18
},
19
19
"jest": {
20
20
"preset": "react-native"
21
21
}
22
+
}
22
23
```
23
24
24
25
_Note: If you are upgrading your react-native application and previously used the `jest-react-native` preset, remove the dependency from your `package.json` file and change the preset to `react-native` instead._
@@ -29,7 +30,7 @@ Run `yarn test` to run tests with Jest.
29
30
30
31
Let's create a [snapshot test](SnapshotTesting.md) for a small intro component with a few views and text components and some styles:
Now let's use React's test renderer and Jest's snapshot feature to interact with the component and capture the rendered output and create a snapshot file:
71
72
72
-
```javascript
73
+
```tsx
73
74
// __tests__/Intro-test.js
74
75
importReactfrom'react';
75
76
importrendererfrom'react-test-renderer';
@@ -138,9 +139,11 @@ The [`transformIgnorePatterns`](configuration.html#transformignorepatterns-array
138
139
By default the jest-react-native preset only processes the project's own source files and react-native. If you have npm dependencies that have to be transformed you can customize this configuration option by including modules other than react-native:
@@ -152,8 +155,10 @@ If you'd like to provide additional configuration for every test file, the [`set
152
155
The [`moduleNameMapper`](configuration.html#modulenamemapper-objectstring-string--arraystring) can be used to map a module path to a different module. By default the preset maps all images to an image stub module but if a module cannot be found this configuration option can help:
Copy file name to clipboardExpand all lines: website/versioned_docs/version-22.x/SnapshotTesting.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ A typical snapshot test case renders a UI component, takes a snapshot, then comp
12
12
13
13
A similar approach can be taken when it comes to testing your React components. Instead of rendering the graphical UI, which would require building the entire app, you can use a test renderer to quickly generate a serializable value for your React tree. Consider this [example test](https://github.com/facebook/jest/blob/master/examples/snapshot/__tests__/link.react.test.js) for a [Link component](https://github.com/facebook/jest/blob/master/examples/snapshot/Link.react.js):
14
14
15
-
```javascript
15
+
```tsx
16
16
importReactfrom'react';
17
17
importrendererfrom'react-test-renderer';
18
18
importLinkfrom'../Link.react';
@@ -52,7 +52,7 @@ It's straightforward to spot when a snapshot test fails after a bug has been int
52
52
53
53
One such situation can arise if we intentionally change the address the Link component in our example is pointing to.
54
54
55
-
```javascript
55
+
```tsx
56
56
// Updated test case with a Link to a different address
Copy file name to clipboardExpand all lines: website/versioned_docs/version-22.x/TutorialReact.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -61,7 +61,7 @@ Your `package.json` should look something like this (where `<current-version>` i
61
61
62
62
Let's create a [snapshot test](SnapshotTesting.md) for a Link component that renders hyperlinks:
63
63
64
-
```javascript
64
+
```tsx
65
65
// Link.react.js
66
66
importReactfrom'react';
67
67
@@ -107,7 +107,7 @@ export default class Link extends React.Component {
107
107
108
108
Now let's use React's test renderer and Jest's snapshot feature to interact with the component and capture the rendered output and create a snapshot file:
109
109
110
-
```javascript
110
+
```tsx
111
111
// Link.react.test.js
112
112
importReactfrom'react';
113
113
importrendererfrom'react-test-renderer';
@@ -197,7 +197,7 @@ React 16 triggers these warnings due to how it checks element types, and the moc
2. Render as a custom element. DOM"custom elements" aren't checked for anything and shouldn't fire warnings. They are lowercase and have a dash in the name.
3. Use `react-test-renderer`. The test renderer doesn't care about element types and will happily accept e.g. `SomeComponent`. You could check snapshots using the test renderer, and check component behavior separately using Enzyme.
@@ -217,7 +217,7 @@ You have to run `yarn add --dev @testing-library/react` to use react-testing-lib
217
217
218
218
Let's implement a checkbox which swaps between two labels:
@@ -282,7 +282,7 @@ You have to run `yarn add --dev enzyme` to use Enzyme. If you are using a React
282
282
283
283
Let's rewrite the test from above using Enzyme instead of react-testing-library. We use Enzyme's [shallow renderer](http://airbnb.io/enzyme/docs/api/shallow.html) in this example.
Copy file name to clipboardExpand all lines: website/versioned_docs/version-22.x/TutorialReactNative.md
+13-8Lines changed: 13 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,13 +13,14 @@ Get a deeper insight into testing a working React Native app example by reading
13
13
Starting from react-native version 0.38, a Jest setup is included by default when running `react-native init`. The following configuration should be automatically added to your package.json file:
14
14
15
15
```json
16
-
// package.json
16
+
{
17
17
"scripts": {
18
18
"test": "jest"
19
19
},
20
20
"jest": {
21
21
"preset": "react-native"
22
22
}
23
+
}
23
24
```
24
25
25
26
_Note: If you are upgrading your react-native application and previously used the `jest-react-native` preset, remove the dependency from your `package.json` file and change the preset to `react-native` instead._
@@ -30,7 +31,7 @@ Run `yarn test` to run tests with Jest.
30
31
31
32
Let's create a [snapshot test](SnapshotTesting.md) for a small intro component with a few views and text components and some styles:
Now let's use React's test renderer and Jest's snapshot feature to interact with the component and capture the rendered output and create a snapshot file:
72
73
73
-
```javascript
74
+
```tsx
74
75
// __tests__/Intro-test.js
75
76
importReactfrom'react';
76
77
importrendererfrom'react-test-renderer';
@@ -139,9 +140,11 @@ The [`transformIgnorePatterns`](configuration.html#transformignorepatterns-array
139
140
By default the jest-react-native preset only processes the project's own source files and react-native. If you have npm dependencies that have to be transformed you can customize this configuration option by including modules other than react-native:
@@ -153,8 +156,10 @@ If you'd like to provide additional configuration for every test file, the [`set
153
156
The [`moduleNameMapper`](configuration.html#modulenamemapper-objectstring-string) can be used to map a module path to a different module. By default the preset maps all images to an image stub module but if a module cannot be found this configuration option can help:
0 commit comments