@@ -30,16 +30,16 @@ In prior setups, react-tools was needed. This is not longer the case. You will n
30
30
Lastly, anywhere you have the following, needs to be replaced with this:
31
31
32
32
``` js
33
- var React = require (' react/addons' );
34
- var TestUtils = React .addons .TestUtils ;
33
+ var React = require (' react/addons' )
34
+ var TestUtils = React .addons .TestUtils
35
35
```
36
36
37
37
with this:
38
38
39
39
``` js
40
- var TestUtils = require ( ' react-addons-test-utils ' );
41
- var ReactDOM = require ( ' react-dom' );
42
- var React = require ( ' react' );
40
+ import React from ' react'
41
+ import ReactDOM from ' react-dom'
42
+ import TestUtils from ' react-addons-test-utils '
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.
@@ -66,75 +66,68 @@ Lastly ensure you are using babel-jest for the script preproccessor:
66
66
67
67
Example:
68
68
----------------------------------------------
69
+
69
70
A component:
71
+
70
72
``` js
71
73
// ../components/BasicPage.js
72
74
73
- let React = require (' react' );
74
-
75
- import { Button } from ' react-bootstrap' ;
76
- import { Link } from ' react-router' ;
77
-
78
- let BasicPage =
79
- React .createClass ({
80
- propTypes: {
81
- authenticated: React .PropTypes .bool ,
82
- },
83
- render : function (){
84
- let mainContent;
85
- let authenticated = this .props .authenticated ;
86
-
87
- if (authenticated) {
88
- mainContent = (
89
- < div>
90
- < Link to= " /admin" >< Button bsStyle= " primary" > Login< / Button>< / Link>
91
- < / div>
92
- );
93
- } else {
94
- mainContent = (
95
- < div>
96
- < Link to= " /admin" >< Button bsStyle= " primary" > Login< / Button>< / Link>
97
- < / div>
98
- );
99
-
100
- }
101
-
102
- return (
103
- < div>
104
- {mainContent}
105
- < / div>
106
- );
107
- },
108
- });
109
- module .exports = BasicPage;
75
+ import React , { Component , PropTypes } from ' react'
76
+ import { Button } from ' react-bootstrap'
77
+ import { Link } from ' react-router'
78
+
79
+
80
+ export default class BasicPage extends Component {
81
+ static propTypes = {
82
+ authenticated: PropTypes .bool
83
+ }
84
+
85
+ render () {
86
+ return (
87
+ < div>
88
+ { this .props .authenticated ? (
89
+ < div>
90
+ < Link to= " /admin" >< Button bsStyle= " primary" > Login< / Button>< / Link>
91
+ < / div>
92
+ ) : (
93
+ < div>
94
+ < Link to= " /admin" >< Button bsStyle= " primary" > Login< / Button>< / Link>
95
+ < / div>
96
+ )
97
+ }
98
+ < / div>
99
+ )
100
+ }
101
+ }
110
102
```
111
103
112
104
The test for that component:
105
+
113
106
``` js
114
107
// ../components/__tests__/BasicPage-test.js
115
108
116
109
// NOTE: cannot use es6 modules syntax because
117
110
// jest.dontMock & jest.autoMockOff()
118
111
// do not understand ES6 modules yet
119
112
120
- jest .dontMock (' ../BasicPage' );
113
+ jest .dontMock (' ../BasicPage' )
121
114
122
115
describe (' BasicPage' , function () {
123
- let BasicPage = require (' ../BasicPage' );
124
- let TestUtils = require (' react-addons-test-utils' );
125
- let ReactDOM = require (' react-dom' );
126
- let React = require (' react' );
116
+ let BasicPage = require (' ../BasicPage' )
117
+ let TestUtils = require (' react-addons-test-utils' )
118
+ let ReactDOM = require (' react-dom' )
119
+ let React = require (' react' )
127
120
128
121
it (' renders the Login button if not logged in' , function () {
129
- let page = TestUtils .renderIntoDocument (< BasicPage / > );
130
- let button = TestUtils .findRenderedDOMComponentWithTag (page, ' button' );
131
- expect (ReactDOM .findDOMNode (button).textContent ).toBe (' Login' );
132
- });
122
+ let page = TestUtils .renderIntoDocument (< BasicPage / > )
123
+ let button = TestUtils .findRenderedDOMComponentWithTag (page, ' button' )
124
+ expect (ReactDOM .findDOMNode (button).textContent ).toBe (' Login' )
125
+ })
133
126
134
127
it (' renders the Account button if logged in' , function () {
135
- let page = TestUtils .renderIntoDocument (< BasicPage authenticated= {true } / > );
136
- let button = TestUtils .findRenderedDOMComponentWithTag (page, ' button' );
137
- expect (ReactDOM .findDOMNode (button).textContent ).toBe (' Your Account' );
138
- });
139
- });
128
+ let page = TestUtils .renderIntoDocument (< BasicPage authenticated= {true } / > )
129
+ let button = TestUtils .findRenderedDOMComponentWithTag (page, ' button' )
130
+ expect (ReactDOM .findDOMNode (button).textContent ).toBe (' Your Account' )
131
+ })
132
+ })
140
133
```
0 commit comments