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:
55- Upgraded to React-Redux 5.
66- Upgraded to Webpack 4.
77- 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/.
99- Package control using Yarn instead of NPM.
1010- Added support for JS object rest spread (...destructuring) and class properties.
1111
Original file line number Diff line number Diff line change @@ -4,11 +4,25 @@ export default class App extends Component {
44
55 constructor ( props ) {
66 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+ } ) ;
717 }
818
919 render ( ) {
20+ const buttonText = this . state . buttonText ;
1021 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 >
1226 ) ;
1327 }
1428}
Original file line number Diff line number Diff line change 11import React from 'react' ;
2+ import {
3+ mountComponentWithRedux
4+ } from '../../test_helper' ;
25import App from './app' ;
3- import { shallow } from 'enzyme' ;
6+
47
58describe (
6- 'App' ,
9+ 'Components:: App' ,
710 ( ) => {
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+ ) ;
829 it (
9- 'renders correctly ' ,
30+ 'button is clickable ' ,
1031 ( ) => {
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!' ) ;
1734 }
1835 ) ;
1936 }
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