File tree Expand file tree Collapse file tree 4 files changed +62
-11
lines changed Expand file tree Collapse file tree 4 files changed +62
-11
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ This fork contains the following updates as of 3/28/2018:
5
5
- Upgraded to React-Redux 5.
6
6
- Upgraded to Webpack 4.
7
7
- Changed babel preset to 'env': https://www.npmjs.com/package/babel-preset-env
8
- - Moved from using Mocha/Chai to Jest/Enzyme.
8
+ - Moved from using Mocha/Chai to Jest/Enzyme. Demo test is within src/components/.
9
9
- Package control using Yarn instead of NPM.
10
10
- Added support for JS object rest spread (...destructuring) and class properties.
11
11
Original file line number Diff line number Diff line change @@ -4,11 +4,25 @@ export default class App extends Component {
4
4
5
5
constructor ( props ) {
6
6
super ( props ) ;
7
+ this . state = {
8
+ buttonText : 'Get Started!'
9
+ } ;
10
+ this . handleGetStarted = this . handleGetStarted . bind ( this ) ;
11
+ }
12
+
13
+ handleGetStarted ( ) {
14
+ this . setState ( {
15
+ 'buttonText' : 'Started!'
16
+ } ) ;
7
17
}
8
18
9
19
render ( ) {
20
+ const buttonText = this . state . buttonText ;
10
21
return (
11
- < div > Redux Simple Starter</ div >
22
+ < div >
23
+ < h1 > Redux Simple Starter</ h1 >
24
+ < button className = "get-started" onClick = { this . handleGetStarted } > { buttonText } </ button >
25
+ </ div >
12
26
) ;
13
27
}
14
28
}
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
+ import {
3
+ mountComponentWithRedux
4
+ } from '../../test_helper' ;
2
5
import App from './app' ;
3
- import { shallow } from 'enzyme' ;
6
+
4
7
5
8
describe (
6
- 'App' ,
9
+ 'Components:: App' ,
7
10
( ) => {
11
+ let component ;
12
+ beforeEach (
13
+ ( ) => {
14
+ component = mountComponentWithRedux ( App ) ;
15
+ }
16
+ ) ;
17
+ it (
18
+ 'renders' ,
19
+ ( ) => {
20
+ expect ( component . exists ( ) ) . toBe ( true ) ;
21
+ }
22
+ ) ;
23
+ it (
24
+ 'renders button' ,
25
+ ( ) => {
26
+ expect ( component . find ( '.get-started' ) . exists ( ) ) . toBe ( true ) ;
27
+ }
28
+ ) ;
8
29
it (
9
- 'renders correctly ' ,
30
+ 'button is clickable ' ,
10
31
( ) => {
11
- // `yarn test`, or `yarn test:watch` to run
12
- // More examples here:
13
- // https://github.com/vjwilson/enzyme-example-jest/blob/master/src/__tests__/Foo-test.js
14
- expect (
15
- shallow ( < App /> ) . contains ( < div > Redux Simple Starter</ div > )
16
- ) . toBe ( true ) ;
32
+ component . find ( '.get-started' ) . simulate ( 'click' ) ;
33
+ expect ( component . find ( '.get-started' ) . text ( ) ) . toEqual ( 'Started!' ) ;
17
34
}
18
35
) ;
19
36
}
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import { Provider } from 'react-redux' ;
3
+ import { createStore } from 'redux' ;
4
+ import { mount } from 'enzyme' ;
5
+ import reducers from './src/reducers' ;
6
+
7
+ function mountComponentWithRedux (
8
+ ComponentClass ,
9
+ state = { } ,
10
+ props = { }
11
+ ) {
12
+ const componentInstance = mount ( // produces app by going through full React lifecycle
13
+ < Provider store = { createStore ( reducers , state ) } >
14
+ < ComponentClass { ...props } />
15
+ </ Provider >
16
+ ) ;
17
+ return componentInstance ;
18
+ }
19
+
20
+ export { mountComponentWithRedux } ;
You can’t perform that action at this time.
0 commit comments