Created
December 23, 2017 00:41
-
-
Save erichulburd/898ecee947475d741283ff0695730845 to your computer and use it in GitHub Desktop.
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
context('user will lose', () => { | |
afterEach(() => { | |
Observable.interval.restore(); | |
}); | |
it('does not restart game when ongoing and emits end event when user loses', () => { | |
const testScheduler = new TestScheduler((actual, expected) => { | |
expect(actual).to.deep.equal(expected); | |
}); | |
const interval$ = testScheduler.createColdObservable('--a--b', { | |
a: 0, | |
a: 1 | |
}); | |
sinon.stub(Observable, 'interval').returns(interval$); | |
const action$ = new ActionsObservable( | |
// Our overly eager user has started the game twice! | |
testScheduler.createHotObservable('aa', { | |
a: actions.start.click() | |
}) | |
); | |
const store = { | |
getState: () => ({}) | |
}; | |
const getState = sinon.stub(store, 'getState'); | |
const now = moment(); | |
[ | |
// This allows the start action to pass through the filter to start the interval | |
{ /* game is not ongoing */ }, | |
// the second call to actions.start.click() will be filtered out b/c game already started. | |
{ /* game is ongoing */ }, | |
// the third call, the interval will incrementTime and filter will see game should not end. | |
{ /* game started but user has not lost */ }, | |
// the fourth call, the interval will incrementTime and filter will see that game should end. | |
{ /* game is ongoing but the user has lost */ } | |
].forEach((gameState, i) => getState.onCall(i).returns({ game: gameState })); | |
const test$ = game(action$, store); | |
testScheduler.expectObservable(test$).toBe('', { | |
// actions the epic emits | |
}); | |
testScheduler.flush(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment