Skip to content

Commit

Permalink
fix: rename runSubscription to execSubscription
Browse files Browse the repository at this point in the history
  • Loading branch information
atheck committed Sep 25, 2023
1 parent b763e7a commit 55202db
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 */ }));
Expand All @@ -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
Expand All @@ -974,7 +974,7 @@ it("dispatches the eventTriggered message", async () => {
expect(mockDispatch).toHaveBeenCalledWith(Msg.eventTriggered());

// Dispose the subscriptions if required
dispose?.();
dispose();
});
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Message } from "../Types";
import { Subscription } from "../useElmish";
import { execCmdWithDispatch } from "./execCmd";

function runSubscription<TProps, TModel, TMessage extends Message>(
function execSubscription<TProps, TModel, TMessage extends Message>(
subscription: Subscription<TProps, TModel, TMessage> | undefined,
dispatch: Dispatch<TMessage>,
model: TModel,
Expand All @@ -24,4 +24,4 @@ function runSubscription<TProps, TModel, TMessage extends Message>(
return dispose ?? noop;
}

export { runSubscription };
export { execSubscription };
4 changes: 2 additions & 2 deletions src/Testing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ 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 };

export {
createModelAndProps,
createUpdateArgsFactory,
execCmd,
execSubscription,
getCreateModelAndProps,
getCreateUpdateArgs,
getUpdateAndExecCmdFn,
getUpdateFn,
initAndExecCmd,
renderWithModel,
runSubscription,
};

0 comments on commit 55202db

Please sign in to comment.