Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.