diff --git a/.changeset/honest-tools-shave.md b/.changeset/honest-tools-shave.md new file mode 100644 index 0000000000..9f9aeacb2e --- /dev/null +++ b/.changeset/honest-tools-shave.md @@ -0,0 +1,5 @@ +--- +'@xstate/vue': patch +--- + +Fix `send(…)` type for `useActor(…)` diff --git a/packages/xstate-vue/src/useActor.ts b/packages/xstate-vue/src/useActor.ts index e9ec30a131..d388cce3a3 100644 --- a/packages/xstate-vue/src/useActor.ts +++ b/packages/xstate-vue/src/useActor.ts @@ -15,7 +15,7 @@ export function useActor( options?: ActorOptions ): { snapshot: Ref>; - send: (event: Actor['send']) => void; + send: Actor['send']; actorRef: Actor; }; export function useActor( diff --git a/packages/xstate-vue/test/UseActorWithTransitionLogic.vue b/packages/xstate-vue/test/UseActorWithTransitionLogic.vue new file mode 100644 index 0000000000..1a2b9d978d --- /dev/null +++ b/packages/xstate-vue/test/UseActorWithTransitionLogic.vue @@ -0,0 +1,28 @@ + + + diff --git a/packages/xstate-vue/test/useActor.test.ts b/packages/xstate-vue/test/useActor.test.ts index c3bd8a4a4d..8213b66de1 100644 --- a/packages/xstate-vue/test/useActor.test.ts +++ b/packages/xstate-vue/test/useActor.test.ts @@ -1,5 +1,6 @@ -import { render } from '@testing-library/vue'; +import { fireEvent, render } from '@testing-library/vue'; import UseActorWithInitiallyInvokedChild from './UseActorWithInitiallyInvokedChild.vue'; +import UseActorWithTransitionLogic from './UseActorWithTransitionLogic.vue'; describe('useActor', () => { it('initial invoked actor should be immediately available', async () => { @@ -11,4 +12,15 @@ describe('useActor', () => { expect(machineSnapshotEl.textContent).toBe('active'); expect(actorSnapshotEl.textContent).toBe('active'); }); + + it('should be able to spawn an actor from actor logic', async () => { + const { getByTestId } = render(UseActorWithTransitionLogic); + const button = getByTestId('count'); + + expect(button.textContent).toEqual('0'); + + await fireEvent.click(button); + + expect(button.textContent).toEqual('1'); + }); });