Skip to content

Commit

Permalink
Add an extra test case for correct action execution when it is provid…
Browse files Browse the repository at this point in the history
…ed in render (#4434)
  • Loading branch information
Andarist authored Nov 7, 2023
1 parent 37d8793 commit 74179ee
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions packages/xstate-react/test/useActorRef.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -505,4 +505,54 @@ describeEachReactMode('useActorRef (%s)', ({ suiteKey, render }) => {
render(<Test />);
}
);

it("should execute action bound to a specific machine's instance when the action is provided in render", () => {
const spy1 = jest.fn();
const spy2 = jest.fn();

const machine = createMachine({
on: {
DO: {
actions: 'stuff'
}
}
});

const Test = () => {
const actorRef1 = useActorRef(
machine.provide({
actions: {
stuff: spy1
}
})
);
useActorRef(
machine.provide({
actions: {
stuff: spy2
}
})
);

return (
<button
type="button"
onClick={() => {
actorRef1.send({
type: 'DO'
});
}}
>
Click
</button>
);
};

render(<Test />);

screen.getByRole('button').click();

expect(spy1).toHaveBeenCalledTimes(1);
expect(spy2).not.toHaveBeenCalled();
});
});

0 comments on commit 74179ee

Please sign in to comment.