1
1
import 'rxjs/add/operator/take' ;
2
- import { Observable } from 'rxjs/Observable' ;
3
2
import { ReflectiveInjector } from '@angular/core' ;
4
3
import { hot } from 'jasmine-marbles' ;
5
4
import { createInjector } from './helpers/injector' ;
6
- import { Store , Action , combineReducers , StoreModule } from '../' ;
7
- import { ActionsSubject } from '../src/private_export' ;
5
+ import { ActionsSubject , ReducerManager , Store , StoreModule } from '../' ;
8
6
import {
9
7
counterReducer ,
10
8
INCREMENT ,
11
9
DECREMENT ,
12
10
RESET ,
13
11
} from './fixtures/counter' ;
12
+ import Spy = jasmine . Spy ;
13
+ import any = jasmine . any ;
14
14
15
15
interface TestAppSchema {
16
16
counter1 : number ;
17
17
counter2 : number ;
18
18
counter3 : number ;
19
- }
20
-
21
- interface Todo { }
22
-
23
- interface TodoAppSchema {
24
- visibilityFilter : string ;
25
- todos : Todo [ ] ;
19
+ counter4 ?: number ;
26
20
}
27
21
28
22
describe ( 'ngRx Store' , ( ) => {
@@ -68,7 +62,7 @@ describe('ngRx Store', () => {
68
62
} ) ;
69
63
} ) ;
70
64
71
- describe ( 'basic store actions' , function ( ) {
65
+ describe ( 'basic store actions' , ( ) => {
72
66
beforeEach ( ( ) => setup ( ) ) ;
73
67
74
68
it ( 'should provide an Observable Store' , ( ) => {
@@ -84,7 +78,7 @@ describe('ngRx Store', () => {
84
78
e : { type : INCREMENT } ,
85
79
} ;
86
80
87
- it ( 'should let you select state with a key name' , function ( ) {
81
+ it ( 'should let you select state with a key name' , ( ) => {
88
82
const counterSteps = hot ( actionSequence , actionValues ) ;
89
83
90
84
counterSteps . subscribe ( action => store . dispatch ( action ) ) ;
@@ -99,7 +93,7 @@ describe('ngRx Store', () => {
99
93
) ;
100
94
} ) ;
101
95
102
- it ( 'should let you select state with a selector function' , function ( ) {
96
+ it ( 'should let you select state with a selector function' , ( ) => {
103
97
const counterSteps = hot ( actionSequence , actionValues ) ;
104
98
105
99
counterSteps . subscribe ( action => store . dispatch ( action ) ) ;
@@ -114,13 +108,13 @@ describe('ngRx Store', () => {
114
108
) ;
115
109
} ) ;
116
110
117
- it ( 'should correctly lift itself' , function ( ) {
111
+ it ( 'should correctly lift itself' , ( ) => {
118
112
const result = store . select ( 'counter1' ) ;
119
113
120
114
expect ( result instanceof Store ) . toBe ( true ) ;
121
115
} ) ;
122
116
123
- it ( 'should increment and decrement counter1' , function ( ) {
117
+ it ( 'should increment and decrement counter1' , ( ) => {
124
118
const counterSteps = hot ( actionSequence , actionValues ) ;
125
119
126
120
counterSteps . subscribe ( action => store . dispatch ( action ) ) ;
@@ -133,7 +127,7 @@ describe('ngRx Store', () => {
133
127
expect ( counterState ) . toBeObservable ( hot ( stateSequence , counter1Values ) ) ;
134
128
} ) ;
135
129
136
- it ( 'should increment and decrement counter1 using the dispatcher' , function ( ) {
130
+ it ( 'should increment and decrement counter1 using the dispatcher' , ( ) => {
137
131
const counterSteps = hot ( actionSequence , actionValues ) ;
138
132
139
133
counterSteps . subscribe ( action => dispatcher . next ( action ) ) ;
@@ -146,7 +140,7 @@ describe('ngRx Store', () => {
146
140
expect ( counterState ) . toBeObservable ( hot ( stateSequence , counter1Values ) ) ;
147
141
} ) ;
148
142
149
- it ( 'should increment and decrement counter2 separately' , function ( ) {
143
+ it ( 'should increment and decrement counter2 separately' , ( ) => {
150
144
const counterSteps = hot ( actionSequence , actionValues ) ;
151
145
152
146
counterSteps . subscribe ( action => store . dispatch ( action ) ) ;
@@ -160,7 +154,7 @@ describe('ngRx Store', () => {
160
154
expect ( counter2State ) . toBeObservable ( hot ( stateSequence , counter2Values ) ) ;
161
155
} ) ;
162
156
163
- it ( 'should implement the observer interface forwarding actions and errors to the dispatcher' , function ( ) {
157
+ it ( 'should implement the observer interface forwarding actions and errors to the dispatcher' , ( ) => {
164
158
spyOn ( dispatcher , 'next' ) ;
165
159
spyOn ( dispatcher , 'error' ) ;
166
160
@@ -171,7 +165,7 @@ describe('ngRx Store', () => {
171
165
expect ( dispatcher . error ) . toHaveBeenCalledWith ( 2 ) ;
172
166
} ) ;
173
167
174
- it ( 'should not be completable' , function ( ) {
168
+ it ( 'should not be completable' , ( ) => {
175
169
const storeSubscription = store . subscribe ( ) ;
176
170
const dispatcherSubscription = dispatcher . subscribe ( ) ;
177
171
@@ -192,4 +186,41 @@ describe('ngRx Store', () => {
192
186
expect ( dispatcherSubscription . closed ) . toBe ( true ) ;
193
187
} ) ;
194
188
} ) ;
189
+
190
+ describe ( `add/remove reducers` , ( ) => {
191
+ let addReducerSpy : Spy ;
192
+ let removeReducerSpy : Spy ;
193
+ const key = 'counter4' ;
194
+
195
+ beforeEach ( ( ) => {
196
+ setup ( ) ;
197
+ const reducerManager = injector . get ( ReducerManager ) ;
198
+ addReducerSpy = spyOn ( reducerManager , 'addReducer' ) . and . callThrough ( ) ;
199
+ removeReducerSpy = spyOn (
200
+ reducerManager ,
201
+ 'removeReducer'
202
+ ) . and . callThrough ( ) ;
203
+ } ) ;
204
+
205
+ it ( `should delegate add/remove to ReducerManager` , ( ) => {
206
+ store . addReducer ( key , counterReducer ) ;
207
+ expect ( addReducerSpy ) . toHaveBeenCalledWith ( key , counterReducer ) ;
208
+
209
+ store . removeReducer ( key ) ;
210
+ expect ( removeReducerSpy ) . toHaveBeenCalledWith ( key ) ;
211
+ } ) ;
212
+
213
+ it ( `should work with added / removed reducers` , ( ) => {
214
+ store . addReducer ( key , counterReducer ) ;
215
+ store . take ( 1 ) . subscribe ( val => {
216
+ expect ( val . counter4 ) . toBe ( 0 ) ;
217
+ } ) ;
218
+
219
+ store . removeReducer ( key ) ;
220
+ store . dispatch ( { type : INCREMENT } ) ;
221
+ store . take ( 1 ) . subscribe ( val => {
222
+ expect ( val . counter4 ) . toBeUndefined ( ) ;
223
+ } ) ;
224
+ } ) ;
225
+ } ) ;
195
226
} ) ;
0 commit comments