1
- import { fromJS } from 'immutable' ;
2
-
3
1
import appReducer from '../reducer' ;
4
- import {
5
- loadRepos ,
6
- reposLoaded ,
7
- repoLoadingError ,
8
- } from '../actions' ;
2
+ import { loadRepos , reposLoaded , repoLoadingError } from '../actions' ;
9
3
10
4
describe ( 'appReducer' , ( ) => {
11
5
let state ;
12
6
beforeEach ( ( ) => {
13
- state = fromJS ( {
7
+ state = {
14
8
loading : false ,
15
9
error : false ,
16
10
currentUser : false ,
17
- userData : fromJS ( {
11
+ userData : {
18
12
repositories : false ,
19
- } ) ,
20
- } ) ;
13
+ } ,
14
+ } ;
21
15
} ) ;
22
16
23
17
it ( 'should return the initial state' , ( ) => {
@@ -26,35 +20,47 @@ describe('appReducer', () => {
26
20
} ) ;
27
21
28
22
it ( 'should handle the loadRepos action correctly' , ( ) => {
29
- const expectedResult = state
30
- . set ( 'loading' , true )
31
- . set ( 'error' , false )
32
- . setIn ( [ 'userData' , 'repositories' ] , false ) ;
33
-
23
+ const expectedResult = {
24
+ ...state ,
25
+ loading : true ,
26
+ error : false ,
27
+ userData : { repositories : false } ,
28
+ } ;
34
29
expect ( appReducer ( state , loadRepos ( ) ) ) . toEqual ( expectedResult ) ;
35
30
} ) ;
36
31
37
32
it ( 'should handle the reposLoaded action correctly' , ( ) => {
38
- const fixture = [ {
39
- name : 'My Repo' ,
40
- } ] ;
33
+ const fixture = [
34
+ {
35
+ name : 'My Repo' ,
36
+ } ,
37
+ ] ;
41
38
const username = 'test' ;
42
- const expectedResult = state
43
- . setIn ( [ 'userData' , 'repositories' ] , fixture )
44
- . set ( 'loading' , false )
45
- . set ( 'currentUser' , username ) ;
39
+ const expectedResult = {
40
+ ...state ,
41
+ loading : false ,
42
+ currentUser : username ,
43
+ userData : { repositories : fixture } ,
44
+ } ;
46
45
47
- expect ( appReducer ( state , reposLoaded ( fixture , username ) ) ) . toEqual ( expectedResult ) ;
46
+ expect ( appReducer ( state , reposLoaded ( fixture , username ) ) ) . toEqual (
47
+ expectedResult ,
48
+ ) ;
48
49
} ) ;
49
50
50
51
it ( 'should handle the repoLoadingError action correctly' , ( ) => {
51
52
const fixture = {
52
53
msg : 'Not found' ,
53
54
} ;
54
- const expectedResult = state
55
- . set ( 'error' , fixture )
56
- . set ( 'loading' , false ) ;
57
55
58
- expect ( appReducer ( state , repoLoadingError ( fixture ) ) ) . toEqual ( expectedResult ) ;
56
+ const expectedResult = {
57
+ ...state ,
58
+ error : fixture ,
59
+ loading : false ,
60
+ } ;
61
+
62
+ expect ( appReducer ( state , repoLoadingError ( fixture ) ) ) . toEqual (
63
+ expectedResult ,
64
+ ) ;
59
65
} ) ;
60
66
} ) ;
0 commit comments