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/guides/testing.md
+23-19Lines changed: 23 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
React Router Testing With Jest
2
2
====================
3
-
Testing has become much easier since React Router version 1.x. For Testing prior React Router versions, see [Old testing docs](https://github.com/rackt/react-router/blob/57543eb41ce45b994a29792d77c86cc10b51eac9/docs/guides/testing.md)
3
+
Testing has become much easier since React Router version 1.x. For Testing prior React Router versions, see [Old testing docs](https://github.com/rackt/react-router/blob/57543eb41ce45b994a29792d77c86cc10b51eac9/docs/guides/testing.md).
4
4
5
5
It is recommended that you read the following two tutorials prior:
6
6
-[Jest Getting Started docs](https://facebook.github.io/jest/docs/getting-started.html)
@@ -12,34 +12,34 @@ Testing with React-Router 1.x should just work. But if you are having issues see
12
12
Updating from testing setup from React-Router 0.x to 1.x
13
13
----------------------------------------------
14
14
Firstly, ensure you are using at least the following versions of each package.
15
-
- "react": "^0.14.0"
16
-
- "react-dom": "^0.14.0"
17
-
- "react-router": "^1.0.0"
18
-
- "react-addons-test-utils": "^0.14.0"
19
-
- "jest-cli": "^0.5.10"
20
-
- "babel-jest": "^5.3.0"
15
+
-`"react": "^0.14.0"`
16
+
-`"react-dom": "^0.14.0"`
17
+
-`"react-router": "^1.0.0"`
18
+
-`"react-addons-test-utils": "^0.14.0"`
19
+
-`"jest-cli": "^0.5.10"`
20
+
-`"babel-jest": "^5.3.0"`
21
21
22
22
Also, make sure you are using node 4.x
23
23
24
24
In prior setups, react-tools was needed. This is not longer the case. You will need to remove it from your package.json and environment.
25
25
26
-
```
26
+
```json
27
27
"react-tools": "~0.13.3",
28
28
```
29
29
30
30
Lastly, anywhere you have the following, needs to be replaced with this:
31
31
32
-
```
33
-
var React = require('react/addons');
34
-
var TestUtils = React.addons.TestUtils;
32
+
```js
33
+
var React =require('react/addons');
34
+
var TestUtils =React.addons.TestUtils;
35
35
```
36
36
37
37
with this:
38
38
39
-
```
40
-
var TestUtils = require('react-addons-test-utils');
41
-
var ReactDOM = require('react-dom');
42
-
var React = require('react');
39
+
```js
40
+
var TestUtils =require('react-addons-test-utils');
41
+
var ReactDOM =require('react-dom');
42
+
var React =require('react');
43
43
```
44
44
45
45
Make sure you do an npm clean, install, etc. and make sure you add react-addons-test-utils and react-dom to your unmocked paths.
@@ -113,13 +113,17 @@ The test for that component:
113
113
```js
114
114
//../components/__tests__/BasicPage-test.js
115
115
116
+
// NOTE: cannot use es6 modules syntax because
117
+
// jest.dontMock & jest.autoMockOff()
118
+
// do not understand ES6 modules yet
119
+
116
120
jest.dontMock('../BasicPage');
117
121
118
122
describe('BasicPage', function() {
119
-
let BasicPage =require('../BasicPage');
120
-
let TestUtils =require('react-addons-test-utils');
121
-
let ReactDOM =require('react-dom');
122
-
let React =require('react');
123
+
let BasicPage =require('../BasicPage');
124
+
let TestUtils =require('react-addons-test-utils');
125
+
let ReactDOM =require('react-dom');
126
+
let React =require('react');
123
127
124
128
it('renders the Login button if not logged in', function() {
125
129
let page =TestUtils.renderIntoDocument(<BasicPage />);
0 commit comments