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