@@ -5,13 +5,19 @@ import 'package:test/test.dart';
5
5
import 'test_actions.dart' ;
6
6
import 'test_state.dart' ;
7
7
8
+ class SingleTestThunk {}
9
+
10
+ class DoubleTestThunk {}
11
+
8
12
void main () {
9
- group ('Create reducer' , () {
10
- Reducer <TestState > reducer;
13
+ group ('create reducer' , () {
11
14
final TestState initialState = TestState (items: List .unmodifiable ([]));
15
+
16
+ Reducer <TestState > testStateReducer;
17
+ Reducer <int > listReducer;
12
18
13
19
setUp (() {
14
- reducer = createReducer <TestState >(initialState, (builder) {
20
+ testStateReducer = createReducer <TestState >(initialState, (builder) {
15
21
builder
16
22
.addCase <RequestItemsAction >(
17
23
(state, action) => state.copyWith (isLoading: true ))
@@ -20,15 +26,23 @@ void main() {
20
26
.addCase <FetchItemsErrorAction >((state, action) =>
21
27
state.copyWith (isLoading: false , error: action.error));
22
28
});
29
+
30
+ listReducer = createReducer <int >(0 , (builder) {
31
+ builder
32
+ .addCase <Fulfilled <SingleTestThunk , String , void >>(
33
+ (state, action) => 1 )
34
+ .addCase <Fulfilled <DoubleTestThunk , String , void >>(
35
+ (state, action) => 2 );
36
+ });
23
37
});
24
38
25
39
test ('should yield the initialState' , () {
26
- final result = reducer (initialState, SomeUnhandledAction ());
40
+ final result = testStateReducer (initialState, SomeUnhandledAction ());
27
41
expect (result, equals (initialState));
28
42
});
29
43
30
44
test ('should yield a loading state' , () {
31
- final result = reducer (initialState, RequestItemsAction ());
45
+ final result = testStateReducer (initialState, RequestItemsAction ());
32
46
expect (result.isLoading, isTrue);
33
47
});
34
48
@@ -39,7 +53,7 @@ void main() {
39
53
]);
40
54
41
55
final prevState = initialState.copyWith (isLoading: true );
42
- final result = reducer (
56
+ final result = testStateReducer (
43
57
prevState,
44
58
FetchItemsSuccessfulAction (
45
59
payload: items,
@@ -55,7 +69,7 @@ void main() {
55
69
]);
56
70
57
71
final prevState = initialState.copyWith (isLoading: true );
58
- final result = reducer (
72
+ final result = testStateReducer (
59
73
prevState,
60
74
FetchItemsSuccessfulAction (
61
75
payload: items,
@@ -68,7 +82,7 @@ void main() {
68
82
final error = Exception ("Hehe you failed" );
69
83
70
84
final prevState = initialState.copyWith (isLoading: true );
71
- final result = reducer (
85
+ final result = testStateReducer (
72
86
prevState,
73
87
FetchItemsErrorAction (
74
88
error: error,
@@ -81,13 +95,31 @@ void main() {
81
95
final error = Exception ("Hehe you failed" );
82
96
83
97
final prevState = initialState.copyWith (isLoading: true );
84
- final result = reducer (
98
+ final result = testStateReducer (
85
99
prevState,
86
100
FetchItemsErrorAction (
87
101
error: error,
88
102
));
89
103
90
104
expect (result.error, equals (error));
91
105
});
106
+
107
+ test ('should yield list with only SingleTestThunk' , () {
108
+ final result = listReducer (
109
+ 0 ,
110
+ Fulfilled <SingleTestThunk , String , void >('SingleTestThunk' , null ),
111
+ );
112
+
113
+ expect (result, equals (1 ));
114
+ });
115
+
116
+ test ('should yield list with only DoubleTestThunk' , () {
117
+ final result = listReducer (
118
+ 0 ,
119
+ Fulfilled <DoubleTestThunk , String , void >('DoubleTestThunk' , null ),
120
+ );
121
+
122
+ expect (result, equals (2 ));
123
+ });
92
124
});
93
125
}
0 commit comments