Skip to content

Commit 46cfb07

Browse files
committed
Add test for optional payloads
1 parent 00ff8a7 commit 46cfb07

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

packages/xstate-store/test/store.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,26 @@ it('events can be emitted with no payload', () => {
376376
expect(spy).toHaveBeenCalledWith({ type: 'incremented' });
377377
});
378378

379+
it('events can be emitted with optional payloads (type check)', () => {
380+
createStore({
381+
emits: {
382+
optionalPayload: (_: { payload?: string }) => {}
383+
},
384+
context: {},
385+
on: {
386+
inc: (_ctx, _ev, enq) => {
387+
enq.emit
388+
// @ts-expect-error
389+
.optionalPayload();
390+
391+
enq.emit.optionalPayload({ payload: 'hello' });
392+
393+
enq.emit.optionalPayload({});
394+
}
395+
}
396+
});
397+
});
398+
379399
it('effects can be enqueued', async () => {
380400
const store = createStore({
381401
context: {

0 commit comments

Comments
 (0)