1- import { createCycleMiddleware } from '../' ;
2- import { createStore , applyMiddleware } from 'redux' ;
3- import xs from 'xstream' ;
4- jest . useFakeTimers ( ) ;
1+ /* eslint-disable no-undef */
2+ import { createCycleMiddleware } from '../'
3+ import { createStore , applyMiddleware } from 'redux'
4+ import xs from 'xstream'
5+ jest . useFakeTimers ( )
56
67function initStore ( main , drivers , reducer = null ) {
7- const rootReducer = reducer || ( ( state = [ ] , action ) => state . concat ( action ) ) ;
8- const cycleMiddleware = createCycleMiddleware ( main , drivers ) ;
8+ const rootReducer = reducer || ( ( state = [ ] , action ) => state . concat ( action ) )
9+ const cycleMiddleware = createCycleMiddleware ( main , drivers )
910 const store = createStore (
1011 rootReducer ,
1112 applyMiddleware ( cycleMiddleware )
12- ) ;
13- return store ;
13+ )
14+ return store
1415}
1516
1617describe ( 'Redux cycle middleware' , ( ) => {
1718 it ( 'dispatches a PING to see whether the middleware dispatches a PONG' , ( done ) => {
1819 function main ( sources ) {
1920 const pong$ = sources . ACTION
2021 . filter ( action => action . type === 'PING' )
21- . mapTo ( { type : 'PONG' } ) ;
22+ . mapTo ( { type : 'PONG' } )
2223
2324 return {
2425 ACTION : pong$
@@ -36,19 +37,19 @@ describe('Redux cycle middleware', () => {
3637
3738 expect ( store . getState ( ) ) . toMatchObject ( expectedActions )
3839
39- done ( ) ;
40+ done ( )
4041 } )
4142
4243 it ( 'dispatches a PING to see whether the middleware dispatches a PONG after 10 seconds' , ( done ) => {
4344 function main ( sources ) {
4445 const pong$ = sources . ACTION
4546 . filter ( action => action . type === 'PING' )
46- . map ( a =>
47+ . map ( ( ) =>
4748 xs . periodic ( 10000 )
4849 . take ( 1 )
4950 . mapTo ( { type : 'PONG' } )
5051 )
51- . flatten ( ) ;
52+ . flatten ( )
5253
5354 return {
5455 ACTION : pong$
@@ -69,36 +70,36 @@ describe('Redux cycle middleware', () => {
6970 { type : 'PING' }
7071 ] )
7172
72- expect ( store . getState ( ) ) . not . toMatchObject ( expectedActions ) ;
73- jest . runAllTimers ( ) ;
74- expect ( setInterval . mock . calls [ 0 ] [ 1 ] ) . toBe ( 10000 ) ;
75- expect ( store . getState ( ) ) . toMatchObject ( expectedActions ) ;
76- done ( ) ;
73+ expect ( store . getState ( ) ) . not . toMatchObject ( expectedActions )
74+ jest . runAllTimers ( )
75+ expect ( setInterval . mock . calls [ 0 ] [ 1 ] ) . toBe ( 10000 )
76+ expect ( store . getState ( ) ) . toMatchObject ( expectedActions )
77+ done ( )
7778 } )
7879
7980 it ( 'dispatches INCREMENT_ASYNC and INCREMENT_IF_ODD actions to check whether state updates correctly' , ( done ) => {
8081 function main ( sources ) {
81- const state$ = sources . STATE ;
82+ const state$ = sources . STATE
8283 const isOdd$ = state$
8384 . map ( state => state % 2 === 1 )
84- . take ( 1 ) ;
85+ . take ( 1 )
8586
8687 const incrementIfOdd$ = sources . ACTION
8788 . filter ( action => action . type === 'INCREMENT_IF_ODD' )
88- . map ( action =>
89+ . map ( ( ) =>
8990 isOdd$
9091 )
9192 . flatten ( )
9293 . filter ( isOdd => isOdd )
93- . mapTo ( { type : 'INCREMENT' } ) ;
94+ . mapTo ( { type : 'INCREMENT' } )
9495
9596 const increment$ = sources . ACTION
9697 . filter ( action => action . type === 'INCREMENT_ASYNC' )
97- . mapTo ( { type : 'INCREMENT' } ) ;
98+ . mapTo ( { type : 'INCREMENT' } )
9899
99100 const decrement$ = sources . ACTION
100101 . filter ( action => action . type === 'DECREMENT_ASYNC' )
101- . mapTo ( { type : 'DECREMENT' } ) ;
102+ . mapTo ( { type : 'DECREMENT' } )
102103
103104 const both$ = xs . merge ( increment$ , decrement$ )
104105
@@ -109,29 +110,29 @@ describe('Redux cycle middleware', () => {
109110
110111 const store = initStore ( main , { } , ( state = 0 , action ) => {
111112 switch ( action . type ) {
112- case 'INCREMENT' :
113- return state + 1 ;
114- case 'DECREMENT' :
115- return state - 1 ;
116- default :
117- return state ;
113+ case 'INCREMENT' :
114+ return state + 1
115+ case 'DECREMENT' :
116+ return state - 1
117+ default :
118+ return state
118119 }
119120 } )
120121
121122 store . dispatch ( { type : 'INCREMENT_ASYNC' } )
122- expect ( store . getState ( ) ) . toBe ( 1 ) ;
123+ expect ( store . getState ( ) ) . toBe ( 1 )
123124 store . dispatch ( { type : 'INCREMENT_ASYNC' } )
124- expect ( store . getState ( ) ) . toBe ( 2 ) ;
125+ expect ( store . getState ( ) ) . toBe ( 2 )
125126 store . dispatch ( { type : 'INCREMENT_ASYNC' } )
126- expect ( store . getState ( ) ) . toBe ( 3 ) ;
127+ expect ( store . getState ( ) ) . toBe ( 3 )
127128 store . dispatch ( { type : 'INCREMENT_IF_ODD' } )
128- expect ( store . getState ( ) ) . toBe ( 4 ) ;
129+ expect ( store . getState ( ) ) . toBe ( 4 )
129130 store . dispatch ( { type : 'INCREMENT_IF_ODD' } )
130- expect ( store . getState ( ) ) . toBe ( 4 ) ;
131+ expect ( store . getState ( ) ) . toBe ( 4 )
131132 store . dispatch ( { type : 'INCREMENT_ASYNC' } )
132- expect ( store . getState ( ) ) . toBe ( 5 ) ;
133+ expect ( store . getState ( ) ) . toBe ( 5 )
133134
134- done ( ) ;
135+ done ( )
135136
136137 } )
137138} )
0 commit comments