File tree Expand file tree Collapse file tree 8 files changed +68
-22
lines changed Expand file tree Collapse file tree 8 files changed +68
-22
lines changed Original file line number Diff line number Diff line change 584584 ],
585585 "actions" : [
586586 " open('src/index.js')"
587+ ],
588+ "hints" : [
589+ " Try this: `npm install --save redux-thunk`"
587590 ]
588591 },
589592 {
590- "description" : " import thunk from \" redux-thunk\" " ,
593+ "description" : " import `reduxThunk` from \" redux-thunk\" " ,
591594 "tests" : [
592595 " 10/02"
596+ ],
597+ "hints" : [
598+ " Try this: `import reduxThunk from 'redux-thunk';`"
593599 ]
594600 },
595601 {
596- "description" : " add thunk to applyMiddleware. The logger should always go last" ,
602+ "description" : " add `reduxThunk` to applyMiddleware. The logger should always go last" ,
597603 "tests" : [
598604 " 10/03"
605+ ],
606+ "hints" : [
607+ " Try this: `applyMiddleware(reduxThunk, logger)`"
599608 ]
600609 },
601610 {
602- "description" : " change the voteUp action creator to return a thunk with the param of \" dispatch\" " ,
611+ "description" : " change the ` voteUp` action creator in \" src/pokemon/index.js \" to return a thunk with the param of \" dispatch\" " ,
603612 "tests" : [
604613 " 10/04"
614+ ],
615+ "hints" : [
616+ " `Try this: `const voteUp => (id) => (dispatch) => {}`'"
605617 ]
606618 },
607619 {
608- "description" : " voteUp should dispatch VOTE_UP" ,
620+ "description" : " voteUp` should dispatch ` VOTE_UP" ,
609621 "tests" : [
610622 " 10/05"
623+ ],
624+ "hints" : [
625+ " Try this: `const voteUp => (id) => (dispatch) => dispatch(voteUp(id))`"
611626 ]
612627 },
613628 {
614- "description" : " voteUp should dispatch sortByPopularity after each vote" ,
629+ "description" : " ` voteUp` should also dispatch ` sortByPopularity after each vote" ,
615630 "tests" : [
616631 " 10/06"
632+ ],
633+ "hints" : [
634+ " Try this: `const voteUp => (id) => (dispatch) => { ... dispatches ... }`" ,
635+ " Add: `dispatch(sortByPopularity());`" ,
636+ " Try this: `const voteUp => (id) => (dispatch) => { dispatch(voteUp(id); dispatch(sortByPopularity()))}`"
617637 ]
618638 }
619639 ],
Original file line number Diff line number Diff line change @@ -5,12 +5,15 @@ chai.use(spies);
55
66let spy = chai . spy . on ( console , 'log' ) ;
77
8- const indexJs = require ( 'BASE/index.js' ) ;
8+ const indexJs = require ( 'BASE/src/index.js' ) ;
9+ const pokemonIndexJs = require ( 'BASE/src/pokemon/index.js' ) ;
10+
11+ const voteUp = pokemonIndexJs . __get__ ( 'voteUp' ) ;
912
1013describe ( '01 redux thunk' , ( ) => {
1114
1215 it ( 'should be installed' , ( ) => {
13- expect ( exist ( 'node_modules/redux-thunk' ) . to . be . true ;
16+ expect ( exists ( 'node_modules/redux-thunk' ) ) . to . be . true ;
1417 } ) ;
1518
1619} ) ;
Original file line number Diff line number Diff line change 1- describe ( '02 thunk ' , ( ) => {
1+ describe ( '02 reduxThunk ' , ( ) => {
22
3- const thunk = indexJs . __get__ ( 'thunk ' ) ;
3+ const reduxThunk = indexJs . __get__ ( 'reduxThunk ' ) ;
44
55 it ( 'should be imported' , ( ) => {
6- expect ( thunk ) . to . not . be . undefined ;
6+ expect ( reduxThunk ) . to . not . be . undefined ;
7+ const regex = / f / ;
8+ expect ( reduxThunk . toString ( ) ) . to . match ( regex ) ;
79 } ) ;
810
9- // more specific check
10-
1111} ) ;
Original file line number Diff line number Diff line change 1- describe ( '03 applyMiddleware thunk' , ( ) => {
2-
1+ describe ( '03 thunk' , ( ) => {
32
3+ it ( 'should be loaded with `applyMiddleware`' , ( ) => {
4+ const regex = / ^ [ a - z ] + \s s t o r e \s ? = .+ a p p l y M i d d l e w a r e \( .* r e d u x T h u n k .* \) / m;
5+ expect ( indexJs . __text__ ) . to . match ( regex ) ;
6+ } ) ;
47
58} ) ;
Original file line number Diff line number Diff line change 11describe ( '04 voteUp' , ( ) => {
22
3+ const voteUp = pokemonIndexJs . __get__ ( 'voteUp' ) ;
4+
5+ it ( 'should return a thunk' , ( ) => {
6+ expect ( typeof voteUp ( 1 ) ) . to . equal ( 'function' ) ;
7+ } ) ;
8+
39 it ( 'should return a thunk with a "dispatch" param' , ( ) => {
4-
10+ const regex = / d i s p a t c h / ;
11+ expect ( voteUp ( 1 ) ) . to . have . length . at . least ( 1 ) ;
12+ expect ( voteUp ( 1 ) . toString ( ) ) . to . match ( regex ) ;
513 } ) ;
614
15+
16+
717} ) ;
Original file line number Diff line number Diff line change 11describe ( '05 voteUp' , ( ) => {
22
33 it ( 'should dispatch a VOTE_UP action' , ( ) => {
4-
4+ const regex = / d i s p a t c h \( \s ? \{ \s ? t y p e \s ? : \s ? V O T E _ U P .* \} \s ? \) / ;
5+ expect ( voteUp ( 1 ) . toString ( ) ) . to . match ( regex ) ;
56 } ) ;
67
78} ) ;
Original file line number Diff line number Diff line change 11describe ( '06 voteUp' , ( ) => {
22
33 it ( 'should dispatch a SORT_BY_POPULARITY action' , ( ) => {
4-
4+ const regex = / d i s p a t c h \s ? \( \s ? s o r t B y P o p u l a r i t y \s ? \( .* \) \s ? \) / m;
5+ expect ( voteUp ( 1 ) . toString ( ) ) . to . match ( regex ) ;
56 } ) ;
67
78} ) ;
Original file line number Diff line number Diff line change @@ -4,20 +4,28 @@ Using thunks for async actions.
44+ install "redux-thunk" as a dependency
55@test ('10/01')
66@action (open('src/index.js'))
7+ @hint ('Try this: ` npm install --save redux-thunk ` ')
78
8- + import thunk from "redux-thunk"
9+ + import ` reduxThunk ` from "redux-thunk"
910@test ('10/02')
11+ @hint ('Try this: ` import reduxThunk from 'redux-thunk'; ` ')
1012
11- + add thunk to applyMiddleware. The logger should always go last
13+ + add ` reduxThunk ` to applyMiddleware. The logger should always go last
1214@test ('10/03')
15+ @hint ('Try this: ` applyMiddleware(reduxThunk, logger) ` ')
1316
14- + change the voteUp action creator to return a thunk with the param of "dispatch"
17+ + change the ` voteUp ` action creator in "src/pokemon/index.js" to return a thunk with the param of "dispatch"
1518@test ('10/04')
19+ @hint (` Try this: ` const voteUp => (id) => (dispatch) => {}`')
1620
17- + voteUp should dispatch VOTE_UP
21+ + ` voteUp ` should dispatch ` VOTE_UP `
1822@test ('10/05')
23+ @hint ('Try this: ` const voteUp => (id) => (dispatch) => dispatch(voteUp(id)) ` ')
1924
20- + voteUp should dispatch sortByPopularity after each vote
25+ + ` voteUp ` should also dispatch ` sortByPopularity after each vote
2126@test ('10/06')
27+ @hint ('Try this: ` const voteUp => (id) => (dispatch) => { ... dispatches ... } ` ')
28+ @hint ('Add: ` dispatch(sortByPopularity()); ` ')
29+ @hint ('Try this: ` const voteUp => (id) => (dispatch) => { dispatch(voteUp(id); dispatch(sortByPopularity()))} ` ')
2230
2331@onPageComplete ('')
You can’t perform that action at this time.
0 commit comments