Skip to content

Commit

Permalink
Add async initialStateFunc test with error
Browse files Browse the repository at this point in the history
  • Loading branch information
Jethro Muller committed Dec 12, 2022
1 parent 514a05d commit 5f9f9a1
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions @nact/core/actor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,31 @@ describe('Actor', function () {
result.should.equal('Cheese! Magical wheels of golden hue!');
});

it('correctly handles an async initial state function which throws an error', async function () {
let handled = false;
let actor = spawn(
system,
function (state, msg) {
if (msg.type === 'query') {
dispatch(msg.sender, state);
return state;
} else if (msg.type === 'append') {
return state + msg.payload;
}
},
{
name: 'Nact',
initialStateFunc: async () => {
await new Promise(f => setTimeout(f, 15));
throw new Error('A bad moon is on the rise');
},
onCrash: (_: any, __: any, ctx: { stop: any; }) => { handled = true; return ctx.stop; }
}
);
await retry(() => isStopped(actor).should.be.true, 12, 10);
handled.should.be.true;
});

it('evalutes in order when returning a promise from a stateful actor function', async function () {
let child = spawn(
system,
Expand Down

0 comments on commit 5f9f9a1

Please sign in to comment.