Skip to content

Commit

Permalink
[core] Add spawned promise error test (#5010)
Browse files Browse the repository at this point in the history
* Add spawned promise error test

* Oops

* Oops again
  • Loading branch information
davidkpiano authored Jul 31, 2024
1 parent 51d4c4f commit b91ad00
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/core/test/actor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1727,4 +1727,30 @@ describe('actors', () => {

expect(spy).toHaveBeenCalledTimes(1);
});

it('catches errors from spawned promise actors', () => {
expect.assertions(1);
const machine = createMachine({
on: {
event: {
actions: assign(({ spawn }) => {
spawn(
fromPromise(async () => {
throw new Error('uh oh');
})
);
})
}
}
});

const actor = createActor(machine);
actor.subscribe({
error: (err) => {
expect((err as Error).message).toBe('uh oh');
}
});
actor.start();
actor.send({ type: 'event' });
});
});

0 comments on commit b91ad00

Please sign in to comment.