Skip to content

Commit

Permalink
Delete redundant tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkpiano committed Mar 24, 2023
1 parent 8a3e3d3 commit fb70dac
Showing 1 changed file with 0 additions and 159 deletions.
159 changes: 0 additions & 159 deletions packages/core/test/invoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,66 +98,6 @@ const fetcherMachine = createMachine({
});

describe('invoke', () => {
it('should start services (external machines)', (done) => {
const childMachine = createMachine({
id: 'child',
initial: 'init',
states: {
init: {
entry: [sendParent({ type: 'INC' }), sendParent({ type: 'INC' })]
}
}
});

const someParentMachine = createMachine<{ count: number }>(
{
id: 'parent',
context: { count: 0 },
initial: 'start',
states: {
start: {
invoke: {
src: 'child',
id: 'someService'
},
always: {
target: 'stop',
guard: (ctx) => ctx.count === 2
},
on: {
INC: {
actions: [
assign({ count: (ctx) => ctx.count + 1 }),
sendTo('someService', { type: 'INC' })
]
}
}
},
stop: {
type: 'final'
}
}
},
{
actors: {
child: childMachine
}
}
);

const actor = interpret(someParentMachine).onDone(() => {
// 1. The 'parent' machine will enter 'start' state
// 2. The 'child' service will be run with ID 'someService'
// 3. The 'child' machine will enter 'init' state
// 4. The 'entry' action will be executed, which sends 'INC' to 'parent' machine twice
// 5. The context will be updated to increment count to 2
expect(actor.getSnapshot().context.count).toEqual(2);
done();
});

actor.start();
});

it('child can immediately respond to the parent with multiple events', () => {
const childMachine = createMachine({
id: 'child',
Expand Down Expand Up @@ -230,105 +170,6 @@ describe('invoke', () => {
service.send({ type: 'FORWARD_DEC' });
});

it('another forwarding pattern', (done) => {
const actual: string[] = [];

const childMachine = createMachine<{ count: number }>({
id: 'child',
context: { count: 0 },
initial: 'counting',
states: {
counting: {
on: {
INCREMENT: [
{
target: 'done',
guard: (ctx) => {
actual.push('child got INCREMENT');
return ctx.count >= 2;
},
actions: assign((ctx) => ({ count: ++ctx.count }))
},
{
target: undefined,
actions: assign((ctx) => ({ count: ++ctx.count }))
}
]
}
},
done: {
type: 'final',
data: (ctx) => ({ countedTo: ctx.count })
}
},
on: {
START: {
actions: () => {
throw new Error('Should not receive START action here.');
}
}
}
});

const parentMachine = createMachine<{ countedTo: number }>({
id: 'parent',
context: { countedTo: 0 },
initial: 'idle',
states: {
idle: {
on: {
START: 'invokeChild'
}
},
invokeChild: {
invoke: {
id: 'child',
src: childMachine,
onDone: {
target: 'done',
actions: assign((_ctx, event) => ({
countedTo: event.data.countedTo
}))
}
},
on: {
INCREMENT: {
actions: [
() => {
actual.push('parent got INCREMENT');
},
sendTo('child', { type: 'INCREMENT' })
]
}
}
},
done: {
type: 'final'
}
}
});

const service = interpret(parentMachine)
.onDone(() => {
expect(service.getSnapshot().context).toEqual({ countedTo: 3 });
expect(actual).toEqual([
'parent got INCREMENT',
'child got INCREMENT',
'parent got INCREMENT',
'child got INCREMENT',
'parent got INCREMENT',
'child got INCREMENT'
]);
done();
})
.start();

service.send({ type: 'START' });
service.send({ type: 'INCREMENT' });
service.send({ type: 'INCREMENT' });
service.send({ type: 'INCREMENT' });
});

it('should start services (explicit machine, invoke = config)', (done) => {
const childMachine = createMachine<{ userId: string | undefined }>({
id: 'fetch',
Expand Down

0 comments on commit fb70dac

Please sign in to comment.