From 55202db9953aa41649cc72f46ecb22e058e25c21 Mon Sep 17 00:00:00 2001 From: Henrik Fuchs Date: Mon, 25 Sep 2023 07:49:06 +0200 Subject: [PATCH] fix: rename `runSubscription` to `execSubscription` --- README.md | 8 ++++---- src/Testing/{runSubscription.ts => execSubscription.ts} | 4 ++-- src/Testing/index.ts | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) rename src/Testing/{runSubscription.ts => execSubscription.ts} (84%) diff --git a/README.md b/README.md index dd91738..3e193a4 100644 --- a/README.md +++ b/README.md @@ -953,10 +953,10 @@ it("returns the correct cmd", async () => { ### Testing subscriptions -It is almost the same as testing the `update` function. You can use the `getCreateModelAndProps` function to create a factory for the model and the props. Then use `runSubscription` to execute the subscriptions: +It is almost the same as testing the `update` function. You can use the `getCreateModelAndProps` function to create a factory for the model and the props. Then use `execSubscription` to execute the subscriptions: ```ts -import { getCreateModelAndProps, runSubscription } from "react-elmish/dist/Testing"; +import { getCreateModelAndProps, execSubscription } from "react-elmish/dist/Testing"; import { init, Msg, subscription } from "./MyComponent"; const createModelAndProps = getCreateModelAndProps(init, () => ({ /* initial props */ })); @@ -965,7 +965,7 @@ it("dispatches the eventTriggered message", async () => { // arrange const mockDispatch = jest.fn(); const args = createModelAndProps({ /* optionally override model here */ }, { /* optionally override props here */ }); - const dispose = runSubscription(subscription, mockDispatch, ...args); + const dispose = execSubscription(subscription, mockDispatch, ...args); // act // Trigger events @@ -974,7 +974,7 @@ it("dispatches the eventTriggered message", async () => { expect(mockDispatch).toHaveBeenCalledWith(Msg.eventTriggered()); // Dispose the subscriptions if required - dispose?.(); + dispose(); }); ``` diff --git a/src/Testing/runSubscription.ts b/src/Testing/execSubscription.ts similarity index 84% rename from src/Testing/runSubscription.ts rename to src/Testing/execSubscription.ts index eda6c04..2575c8c 100644 --- a/src/Testing/runSubscription.ts +++ b/src/Testing/execSubscription.ts @@ -3,7 +3,7 @@ import { Message } from "../Types"; import { Subscription } from "../useElmish"; import { execCmdWithDispatch } from "./execCmd"; -function runSubscription( +function execSubscription( subscription: Subscription | undefined, dispatch: Dispatch, model: TModel, @@ -24,4 +24,4 @@ function runSubscription( return dispose ?? noop; } -export { runSubscription }; +export { execSubscription }; diff --git a/src/Testing/index.ts b/src/Testing/index.ts index ead3d5b..4885b1d 100644 --- a/src/Testing/index.ts +++ b/src/Testing/index.ts @@ -2,11 +2,11 @@ import { RenderWithModelOptions } from "../fakeOptions"; import { createModelAndProps } from "./createModelAndProps"; import { ModelAndPropsFactory, UpdateArgsFactory, createUpdateArgsFactory } from "./createUpdateArgsFactory"; import { execCmd } from "./execCmd"; +import { execSubscription } from "./execSubscription"; import { getCreateModelAndProps, getCreateUpdateArgs } from "./getCreateUpdateArgs"; import { getUpdateAndExecCmdFn, getUpdateFn } from "./getUpdateFn"; import { initAndExecCmd } from "./initAndExecCmd"; import { renderWithModel } from "./renderWithModel"; -import { runSubscription } from "./runSubscription"; export type { ModelAndPropsFactory, RenderWithModelOptions, UpdateArgsFactory }; @@ -14,11 +14,11 @@ export { createModelAndProps, createUpdateArgsFactory, execCmd, + execSubscription, getCreateModelAndProps, getCreateUpdateArgs, getUpdateAndExecCmdFn, getUpdateFn, initAndExecCmd, renderWithModel, - runSubscription, };