diff --git a/deno.lock b/deno.lock index 6baa597..ccff32d 100644 --- a/deno.lock +++ b/deno.lock @@ -4,7 +4,8 @@ "https://crux.land/api/get/2KNRVU": "https://crux.land/api/get/2KNRVU.ts", "https://crux.land/api/get/router@0.0.5": "https://crux.land/api/get/2KNRVU", "https://crux.land/router@0.0.5": "https://crux.land/api/get/router@0.0.5", - "https://esm.sh/v128/@types/react@~18.2/index.d.ts": "https://esm.sh/v128/@types/react@18.2.38/index.d.ts" + "https://esm.sh/v128/@types/react@~18.2/index.d.ts": "https://esm.sh/v128/@types/react@18.2.38/index.d.ts", + "https://esm.sh/v135/@types/react@~18.2/index.d.ts": "https://esm.sh/v135/@types/react@18.2.38/index.d.ts" }, "remote": { "https://crux.land/api/get/2KNRVU.ts": "6a77d55844aba78d01520c5ff0b2f0af7f24cc1716a0de8b3bb6bd918c47b5ba", @@ -156,7 +157,7 @@ "https://deno.land/x/wasmbuild@0.15.0/loader.ts": "d98d195a715f823151cbc8baa3f32127337628379a02d9eb2a3c5902dbccfc02", "https://esm.sh/immer@10.0.2?pin=v122": "7ac87b9c76176de8384a67f8cd93d44f75be1a7496c92707252acb669595c393", "https://esm.sh/react-redux@8.0.5?pin=v122": "fa98e94dc8803fb84bee9eb08a13f11833f634d381003247207682823887dc51", - "https://esm.sh/react@18.2.0?pin=v122": "8950a34a030620fce8349d6bd3913b3bdb186c5ec7968fa5ba4d054e22d78e6c", + "https://esm.sh/react@18.2.0?pin=v122": "04ad7dc6d11fa27b24c136686a334ecdd19e972fae627cd98cbdc13cdac238c2", "https://esm.sh/reselect@4.1.8?pin=v122": "486407fec8db8f0c87ba540ff6457dbec3c8ec8fa93a4845383bc8cdb33c6008", "https://esm.sh/stable/react@18.2.0/denonext/react.mjs": "3c4f23bcfc53b256fcfaf6f834fa9f584c3bb7be667b2682c6cb6ba8ef88f8e6", "https://esm.sh/v122/@babel/runtime@7.22.5/denonext/helpers/esm/extends.js": "3955a0ef35db01cd4efff831a9027924f90fa7d55621cd2b6b8519283e573c21", diff --git a/test/take-helper.test.ts b/test/take-helper.test.ts index a71f8fa..0520bbe 100644 --- a/test/take-helper.test.ts +++ b/test/take-helper.test.ts @@ -68,10 +68,7 @@ it(testEvery, "should receive all actions", async () => { function* root() { const task = yield* spawn(() => - takeEvery( - "ACTION", - (action) => worker("a1", "a2", action), - ) + takeEvery("ACTION", (action) => worker("a1", "a2", action)) ); yield* take("CANCEL_WATCHER"); yield* task.halt(); @@ -113,3 +110,45 @@ it(testEvery, "should receive all actions", async () => { ["a1", "a2", 5], ]); }); + +it(testEvery, "recover from throw", async () => { + const loop = 10; + const actual: string[][] = []; + + function* root() { + const task = yield* spawn(() => + takeEvery("ACTION", (action) => worker("a1", "a2", action)) + ); + yield* take("CANCEL_WATCHER"); + yield* task.halt(); + } + + // deno-lint-ignore require-yield + function* worker(arg1: string, arg2: string, action: AnyAction) { + if (action.payload === 3) throw new Error("random error!"); + actual.push([arg1, arg2, action.payload]); + } + + const store = createStore({ initialState: {} }); + const task = store.run(root); + + for (let i = 1; i <= loop / 2; i += 1) { + store.dispatch({ + type: "ACTION", + payload: i, + }); + } + + await task; + + expect(actual).toEqual([ + ["a1", "a2", 1], + ["a1", "a2", 2], + // this throws so we should miss this one + // ["a1", "a2", 3], + // TODO can we observe the throw in a test? + // takeEvery should continue and still handle follow events + ["a1", "a2", 4], + ["a1", "a2", 5], + ]); +});