Skip to content

Commit

Permalink
Revert "Remove invalid test: The <cancel> element is used to cancel a…
Browse files Browse the repository at this point in the history
… delayed <send> event."

This reverts commit ab4bad0.
  • Loading branch information
Andarist committed Oct 23, 2024
1 parent 898fa99 commit 71324ad
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions packages/core/test/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3771,6 +3771,51 @@ describe('cancel', () => {
await sleep(10);
expect(spy.mock.calls.length).toBe(0);
});

it('should not be able to cancel a just scheduled non-delayed event to a just invoked child', async () => {
const spy = jest.fn();

const child = createMachine({
on: {
PING: {
actions: spy
}
}
});

const machine = setup({
actors: {
child
}
}).createMachine({
initial: 'a',
states: {
a: {
on: {
START: 'b'
}
},
b: {
entry: [
sendTo('myChild', { type: 'PING' }, { id: 'myEvent' }),
cancel('myEvent')
],
invoke: {
src: 'child',
id: 'myChild'
}
}
}
});

const actorRef = createActor(machine).start();

actorRef.send({
type: 'START'
});

expect(spy.mock.calls.length).toBe(1);
});
});

describe('assign action order', () => {
Expand Down

0 comments on commit 71324ad

Please sign in to comment.