-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import {createStore} from '../../' | ||
import pluginDispatch from '../dispatch' | ||
import pluginReducer from '../reducer' | ||
import pluginEpic from '../epic' | ||
|
||
const delay = time => new Promise(resolve => setTimeout(resolve, time)) | ||
|
||
const createStoreWithPlugin = (epic, reducer = state => state) => { | ||
return createStore({}, [ | ||
pluginDispatch(), | ||
pluginReducer(reducer), | ||
pluginEpic(epic) | ||
]) | ||
} | ||
|
||
describe('plugin', () => { | ||
describe('epics', () => { | ||
it('is a function', () => { | ||
expect(typeof pluginEpic).toBe('function') | ||
}) | ||
|
||
it('throws if epic is not a function', () => { | ||
expect(() => { | ||
createStore(123) | ||
}).toThrow() | ||
}) | ||
|
||
it('works', async () => { | ||
const log = [] | ||
const epic = (observable, store) => { | ||
return { | ||
subscribe (sink) { | ||
observable.subscribe({ | ||
next: action => { | ||
if (action.type === 'PING') { | ||
sink.next({type: 'PONG'}) | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
} | ||
const store = createStoreWithPlugin(epic) | ||
const dispatch = store.dispatch | ||
|
||
store.dispatch = (action) => { | ||
log.push(action) | ||
dispatch(action) | ||
} | ||
|
||
await delay(100) | ||
|
||
store.dispatch({ | ||
type: 'PING' | ||
}) | ||
|
||
store.dispatch({ | ||
type: 'NOT_PING' | ||
}) | ||
|
||
expect(log).toEqual([ | ||
{ type: 'PING' }, | ||
{ type: 'PONG' }, | ||
{ type: 'NOT_PING' } | ||
]) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters