Skip to content

Instantly share code, notes, and snippets.

@reime005
Created September 9, 2019 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reime005/4937aa69651a5852aa72b2a38e415d79 to your computer and use it in GitHub Desktop.
Save reime005/4937aa69651a5852aa72b2a38e415d79 to your computer and use it in GitHub Desktop.
/* src/store/__tests__/saga.test.js */
import SagaTester from "redux-saga-tester";
import { rootSaga, queuedSagaAction } from "../rootSaga";
import { rootReducer } from "../rootReducer";
// enable mock api so that test environment goes against fake server
require('../../mock-api.js');
const delay = (t) => new Promise(res => setTimeout(() => res(), t));
describe("root saga", () => {
it("should handle 4 button clicks one after another", async () => {
const sagaTester = new SagaTester({
reducers: rootReducer
});
sagaTester.start(rootSaga);
sagaTester.dispatch(queuedSagaAction());
sagaTester.dispatch(queuedSagaAction());
sagaTester.dispatch(queuedSagaAction());
sagaTester.dispatch(queuedSagaAction());
await delay(5000); // wait for 4 request * max 1sec each
const state = sagaTester.getState();
expect(state.exampleReducer.counter).toEqual(4);
}, 10000);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment