@@ -68,6 +68,53 @@ describe('configureStore', () => {
68
68
} )
69
69
} )
70
70
71
+ describe ( 'given undefined middleware' , ( ) => {
72
+ it ( 'calls createStore with default middleware' , ( ) => {
73
+ expect ( configureStore ( { middleware : undefined , reducer } ) ) . toBeInstanceOf (
74
+ Object
75
+ )
76
+ expect ( redux . applyMiddleware ) . toHaveBeenCalledWith (
77
+ expect . any ( Function ) , // thunk
78
+ expect . any ( Function ) , // immutableCheck
79
+ expect . any ( Function ) // serializableCheck
80
+ )
81
+ expect ( devtools . composeWithDevTools ) . toHaveBeenCalled ( )
82
+ expect ( redux . createStore ) . toHaveBeenCalledWith (
83
+ reducer ,
84
+ undefined ,
85
+ expect . any ( Function )
86
+ )
87
+ } )
88
+ } )
89
+
90
+ describe ( 'given a middleware creation function that returns undefined' , ( ) => {
91
+ it ( 'throws an error' , ( ) => {
92
+ const invalidBuilder = jest . fn ( getDefaultMiddleware => undefined as any )
93
+ expect ( ( ) =>
94
+ configureStore ( { middleware : invalidBuilder , reducer } )
95
+ ) . toThrow (
96
+ 'when using a middleware builder function, an array of middleware must be returned'
97
+ )
98
+ } )
99
+ } )
100
+
101
+ describe ( 'given a middleware creation function that returns an array with non-functions' , ( ) => {
102
+ it ( 'throws an error' , ( ) => {
103
+ const invalidBuilder = jest . fn ( getDefaultMiddleware => [ true ] as any )
104
+ expect ( ( ) =>
105
+ configureStore ( { middleware : invalidBuilder , reducer } )
106
+ ) . toThrow ( 'each middleware provided to configureStore must be a function' )
107
+ } )
108
+ } )
109
+
110
+ describe ( 'given custom middleware that contains non-functions' , ( ) => {
111
+ it ( 'throws an error' , ( ) => {
112
+ expect ( ( ) =>
113
+ configureStore ( { middleware : [ true ] as any , reducer } )
114
+ ) . toThrow ( 'each middleware provided to configureStore must be a function' )
115
+ } )
116
+ } )
117
+
71
118
describe ( 'given custom middleware' , ( ) => {
72
119
it ( 'calls createStore with custom middleware and without default middleware' , ( ) => {
73
120
const thank : redux . Middleware = ( _store ) => ( next ) => ( action ) =>
0 commit comments