File tree 8 files changed +68
-22
lines changed
8 files changed +68
-22
lines changed Original file line number Diff line number Diff line change 584
584
],
585
585
"actions" : [
586
586
" open('src/index.js')"
587
+ ],
588
+ "hints" : [
589
+ " Try this: `npm install --save redux-thunk`"
587
590
]
588
591
},
589
592
{
590
- "description" : " import thunk from \" redux-thunk\" " ,
593
+ "description" : " import `reduxThunk` from \" redux-thunk\" " ,
591
594
"tests" : [
592
595
" 10/02"
596
+ ],
597
+ "hints" : [
598
+ " Try this: `import reduxThunk from 'redux-thunk';`"
593
599
]
594
600
},
595
601
{
596
- "description" : " add thunk to applyMiddleware. The logger should always go last" ,
602
+ "description" : " add `reduxThunk` to applyMiddleware. The logger should always go last" ,
597
603
"tests" : [
598
604
" 10/03"
605
+ ],
606
+ "hints" : [
607
+ " Try this: `applyMiddleware(reduxThunk, logger)`"
599
608
]
600
609
},
601
610
{
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\" " ,
603
612
"tests" : [
604
613
" 10/04"
614
+ ],
615
+ "hints" : [
616
+ " `Try this: `const voteUp => (id) => (dispatch) => {}`'"
605
617
]
606
618
},
607
619
{
608
- "description" : " voteUp should dispatch VOTE_UP" ,
620
+ "description" : " voteUp` should dispatch ` VOTE_UP" ,
609
621
"tests" : [
610
622
" 10/05"
623
+ ],
624
+ "hints" : [
625
+ " Try this: `const voteUp => (id) => (dispatch) => dispatch(voteUp(id))`"
611
626
]
612
627
},
613
628
{
614
- "description" : " voteUp should dispatch sortByPopularity after each vote" ,
629
+ "description" : " ` voteUp` should also dispatch ` sortByPopularity after each vote" ,
615
630
"tests" : [
616
631
" 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()))}`"
617
637
]
618
638
}
619
639
],
Original file line number Diff line number Diff line change @@ -5,12 +5,15 @@ chai.use(spies);
5
5
6
6
let spy = chai . spy . on ( console , 'log' ) ;
7
7
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' ) ;
9
12
10
13
describe ( '01 redux thunk' , ( ) => {
11
14
12
15
it ( 'should be installed' , ( ) => {
13
- expect ( exist ( 'node_modules/redux-thunk' ) . to . be . true ;
16
+ expect ( exists ( 'node_modules/redux-thunk' ) ) . to . be . true ;
14
17
} ) ;
15
18
16
19
} ) ;
Original file line number Diff line number Diff line change 1
- describe ( '02 thunk ' , ( ) => {
1
+ describe ( '02 reduxThunk ' , ( ) => {
2
2
3
- const thunk = indexJs . __get__ ( 'thunk ' ) ;
3
+ const reduxThunk = indexJs . __get__ ( 'reduxThunk ' ) ;
4
4
5
5
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 ) ;
7
9
} ) ;
8
10
9
- // more specific check
10
-
11
11
} ) ;
Original file line number Diff line number Diff line change 1
- describe ( '03 applyMiddleware thunk' , ( ) => {
2
-
1
+ describe ( '03 thunk' , ( ) => {
3
2
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
+ } ) ;
4
7
5
8
} ) ;
Original file line number Diff line number Diff line change 1
1
describe ( '04 voteUp' , ( ) => {
2
2
3
+ const voteUp = pokemonIndexJs . __get__ ( 'voteUp' ) ;
4
+
5
+ it ( 'should return a thunk' , ( ) => {
6
+ expect ( typeof voteUp ( 1 ) ) . to . equal ( 'function' ) ;
7
+ } ) ;
8
+
3
9
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 ) ;
5
13
} ) ;
6
14
15
+
16
+
7
17
} ) ;
Original file line number Diff line number Diff line change 1
1
describe ( '05 voteUp' , ( ) => {
2
2
3
3
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 ) ;
5
6
} ) ;
6
7
7
8
} ) ;
Original file line number Diff line number Diff line change 1
1
describe ( '06 voteUp' , ( ) => {
2
2
3
3
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 ) ;
5
6
} ) ;
6
7
7
8
} ) ;
Original file line number Diff line number Diff line change @@ -4,20 +4,28 @@ Using thunks for async actions.
4
4
+ install "redux-thunk" as a dependency
5
5
@test ('10/01')
6
6
@action (open('src/index.js'))
7
+ @hint ('Try this: ` npm install --save redux-thunk ` ')
7
8
8
- + import thunk from "redux-thunk"
9
+ + import ` reduxThunk ` from "redux-thunk"
9
10
@test ('10/02')
11
+ @hint ('Try this: ` import reduxThunk from 'redux-thunk'; ` ')
10
12
11
- + add thunk to applyMiddleware. The logger should always go last
13
+ + add ` reduxThunk ` to applyMiddleware. The logger should always go last
12
14
@test ('10/03')
15
+ @hint ('Try this: ` applyMiddleware(reduxThunk, logger) ` ')
13
16
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"
15
18
@test ('10/04')
19
+ @hint (` Try this: ` const voteUp => (id) => (dispatch) => {}`')
16
20
17
- + voteUp should dispatch VOTE_UP
21
+ + ` voteUp ` should dispatch ` VOTE_UP `
18
22
@test ('10/05')
23
+ @hint ('Try this: ` const voteUp => (id) => (dispatch) => dispatch(voteUp(id)) ` ')
19
24
20
- + voteUp should dispatch sortByPopularity after each vote
25
+ + ` voteUp ` should also dispatch ` sortByPopularity after each vote
21
26
@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()))} ` ')
22
30
23
31
@onPageComplete ('')
You can’t perform that action at this time.
0 commit comments