1
1
import expect from 'expect' ;
2
2
import { createStore , combineReducers } from '../src/index' ;
3
- import { addTodo , dispatchInMiddle , throwError } from './helpers/actionCreators' ;
3
+ import { addTodo , dispatchInMiddle , throwError , unknownAction } from './helpers/actionCreators' ;
4
4
import * as reducers from './helpers/reducers' ;
5
5
6
6
describe ( 'createStore' , ( ) => {
@@ -48,7 +48,7 @@ describe('createStore', () => {
48
48
const store = createStore ( reducers . todos ) ;
49
49
expect ( store . getState ( ) ) . toEqual ( [ ] ) ;
50
50
51
- store . dispatch ( { } ) ;
51
+ store . dispatch ( unknownAction ( ) ) ;
52
52
expect ( store . getState ( ) ) . toEqual ( [ ] ) ;
53
53
54
54
store . dispatch ( addTodo ( 'Hello' ) ) ;
@@ -77,7 +77,7 @@ describe('createStore', () => {
77
77
text : 'Hello'
78
78
} ] ) ;
79
79
80
- store . dispatch ( { } ) ;
80
+ store . dispatch ( unknownAction ( ) ) ;
81
81
expect ( store . getState ( ) ) . toEqual ( [ {
82
82
id : 1 ,
83
83
text : 'Hello'
@@ -160,43 +160,43 @@ describe('createStore', () => {
160
160
const listenerB = expect . createSpy ( ( ) => { } ) ;
161
161
162
162
let unsubscribeA = store . subscribe ( listenerA ) ;
163
- store . dispatch ( { } ) ;
163
+ store . dispatch ( unknownAction ( ) ) ;
164
164
expect ( listenerA . calls . length ) . toBe ( 1 ) ;
165
165
expect ( listenerB . calls . length ) . toBe ( 0 ) ;
166
166
167
- store . dispatch ( { } ) ;
167
+ store . dispatch ( unknownAction ( ) ) ;
168
168
expect ( listenerA . calls . length ) . toBe ( 2 ) ;
169
169
expect ( listenerB . calls . length ) . toBe ( 0 ) ;
170
170
171
171
const unsubscribeB = store . subscribe ( listenerB ) ;
172
172
expect ( listenerA . calls . length ) . toBe ( 2 ) ;
173
173
expect ( listenerB . calls . length ) . toBe ( 0 ) ;
174
174
175
- store . dispatch ( { } ) ;
175
+ store . dispatch ( unknownAction ( ) ) ;
176
176
expect ( listenerA . calls . length ) . toBe ( 3 ) ;
177
177
expect ( listenerB . calls . length ) . toBe ( 1 ) ;
178
178
179
179
unsubscribeA ( ) ;
180
180
expect ( listenerA . calls . length ) . toBe ( 3 ) ;
181
181
expect ( listenerB . calls . length ) . toBe ( 1 ) ;
182
182
183
- store . dispatch ( { } ) ;
183
+ store . dispatch ( unknownAction ( ) ) ;
184
184
expect ( listenerA . calls . length ) . toBe ( 3 ) ;
185
185
expect ( listenerB . calls . length ) . toBe ( 2 ) ;
186
186
187
187
unsubscribeB ( ) ;
188
188
expect ( listenerA . calls . length ) . toBe ( 3 ) ;
189
189
expect ( listenerB . calls . length ) . toBe ( 2 ) ;
190
190
191
- store . dispatch ( { } ) ;
191
+ store . dispatch ( unknownAction ( ) ) ;
192
192
expect ( listenerA . calls . length ) . toBe ( 3 ) ;
193
193
expect ( listenerB . calls . length ) . toBe ( 2 ) ;
194
194
195
195
unsubscribeA = store . subscribe ( listenerA ) ;
196
196
expect ( listenerA . calls . length ) . toBe ( 3 ) ;
197
197
expect ( listenerB . calls . length ) . toBe ( 2 ) ;
198
198
199
- store . dispatch ( { } ) ;
199
+ store . dispatch ( unknownAction ( ) ) ;
200
200
expect ( listenerA . calls . length ) . toBe ( 4 ) ;
201
201
expect ( listenerB . calls . length ) . toBe ( 2 ) ;
202
202
} ) ;
@@ -214,8 +214,8 @@ describe('createStore', () => {
214
214
} ) ;
215
215
store . subscribe ( listenerC ) ;
216
216
217
- store . dispatch ( { } ) ;
218
- store . dispatch ( { } ) ;
217
+ store . dispatch ( unknownAction ( ) ) ;
218
+ store . dispatch ( unknownAction ( ) ) ;
219
219
220
220
expect ( listenerA . calls . length ) . toBe ( 2 ) ;
221
221
expect ( listenerB . calls . length ) . toBe ( 1 ) ;
@@ -237,7 +237,7 @@ describe('createStore', () => {
237
237
it ( 'should only accept plain object actions' , ( ) => {
238
238
const store = createStore ( reducers . todos ) ;
239
239
expect ( ( ) =>
240
- store . dispatch ( { } )
240
+ store . dispatch ( unknownAction ( ) )
241
241
) . toNotThrow ( ) ;
242
242
243
243
function AwesomeMap ( ) { }
@@ -277,7 +277,7 @@ describe('createStore', () => {
277
277
const store = createStore ( reducers . dispatchInTheMiddleOfReducer ) ;
278
278
279
279
expect ( ( ) =>
280
- store . dispatch ( dispatchInMiddle ( store . dispatch . bind ( store , { } ) ) )
280
+ store . dispatch ( dispatchInMiddle ( store . dispatch . bind ( store , unknownAction ( ) ) ) )
281
281
) . toThrow ( / m a y n o t d i s p a t c h / ) ;
282
282
} ) ;
283
283
@@ -288,7 +288,14 @@ describe('createStore', () => {
288
288
) . toThrow ( ) ;
289
289
290
290
expect ( ( ) =>
291
- store . dispatch ( { } )
291
+ store . dispatch ( unknownAction ( ) )
292
292
) . toNotThrow ( ) ;
293
293
} ) ;
294
+
295
+ it ( 'should only accept actions with a `type`' , ( ) => {
296
+ const store = createStore ( reducers . todos ) ;
297
+ expect ( ( ) =>
298
+ store . dispatch ( { } )
299
+ ) . toThrow ( / A c t i o n s m u s t s p e c i f y a ` t y p e ` / ) ;
300
+ } ) ;
294
301
} ) ;
0 commit comments