-
-
Save reime005/4937aa69651a5852aa72b2a38e415d79 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
/* 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