|
1 | 1 | import { createStore, combineReducers } from '../src/index'
|
2 |
| -import { addTodo, dispatchInMiddle, throwError, unknownAction } from './helpers/actionCreators' |
| 2 | +import { |
| 3 | + addTodo, |
| 4 | + dispatchInMiddle, |
| 5 | + getStateInMiddle, |
| 6 | + subscribeInMiddle, |
| 7 | + unsubscribeInMiddle, |
| 8 | + throwError, |
| 9 | + unknownAction |
| 10 | +} from './helpers/actionCreators' |
3 | 11 | import * as reducers from './helpers/reducers'
|
4 | 12 | import * as Rx from 'rxjs'
|
5 | 13 | import $$observable from 'symbol-observable'
|
@@ -461,6 +469,31 @@ describe('createStore', () => {
|
461 | 469 | ).toThrow(/may not dispatch/)
|
462 | 470 | })
|
463 | 471 |
|
| 472 | + it('does not allow getState() from within a reducer', () => { |
| 473 | + const store = createStore(reducers.getStateInTheMiddleOfReducer) |
| 474 | + |
| 475 | + expect(() => |
| 476 | + store.dispatch(getStateInMiddle(store.getState.bind(store))) |
| 477 | + ).toThrow(/You may not call store.getState()/) |
| 478 | + }) |
| 479 | + |
| 480 | + it('does not allow subscribe() from within a reducer', () => { |
| 481 | + const store = createStore(reducers.subscribeInTheMiddleOfReducer) |
| 482 | + |
| 483 | + expect(() => |
| 484 | + store.dispatch(subscribeInMiddle(store.subscribe.bind(store, () => {}))) |
| 485 | + ).toThrow(/You may not call store.subscribe()/) |
| 486 | + }) |
| 487 | + |
| 488 | + it('does not allow unsubscribe from subscribe() from within a reducer', () => { |
| 489 | + const store = createStore(reducers.unsubscribeInTheMiddleOfReducer) |
| 490 | + const unsubscribe = store.subscribe(() => {}) |
| 491 | + |
| 492 | + expect(() => |
| 493 | + store.dispatch(unsubscribeInMiddle(unsubscribe.bind(store))) |
| 494 | + ).toThrow(/You may not unsubscribe from a store/) |
| 495 | + }) |
| 496 | + |
464 | 497 | it('recovers from an error within a reducer', () => {
|
465 | 498 | const store = createStore(reducers.errorThrowingReducer)
|
466 | 499 | expect(() =>
|
|
0 commit comments