add test for editor saga

This commit is contained in:
David Lechner
2020-06-10 21:59:34 -05:00
committed by David Lechner
parent 31c3e2b52e
commit 5c3ec89e3b
4 changed files with 44 additions and 2 deletions
+10 -2
View File
@@ -3,21 +3,25 @@
import { END, MulticastChannel, Saga, Task, runSaga, stdChannel } from 'redux-saga';
import { Action } from '../src/actions';
import { RootState } from '../src/reducers';
export class AsyncSaga {
private channel: MulticastChannel<Action>;
private dispatches: (Action | END)[];
private takers: { put: (action: Action | END) => void }[];
private channel: MulticastChannel<Action>;
private state: Partial<RootState>;
private task: Task;
public constructor(saga: Saga) {
this.channel = stdChannel();
this.dispatches = [];
this.takers = [];
this.channel = stdChannel();
this.state = {};
this.task = runSaga(
{
channel: this.channel,
dispatch: this.dispatch.bind(this),
getState: () => this.state,
onError: (e) => fail(e),
},
saga,
@@ -56,6 +60,10 @@ export class AsyncSaga {
return Promise.resolve(next);
}
public setState(state: Partial<RootState>): void {
this.state = state;
}
public async end(): Promise<void> {
this.task.cancel();
await this.task.toPromise();