diff --git a/packages/core/test/transient.test.ts b/packages/core/test/transient.test.ts index 8144301fef..1e1647b261 100644 --- a/packages/core/test/transient.test.ts +++ b/packages/core/test/transient.test.ts @@ -255,63 +255,6 @@ describe('transient states (eventless transitions)', () => { expect(actorRef.getSnapshot().value).toEqual({ A: 'A4', B: 'B4' }); }); - it('should execute all eventless transitions in the same microstep (with `always`)', () => { - const machine = createMachine({ - type: 'parallel', - states: { - A: { - initial: 'A1', - states: { - A1: { - on: { - E: 'A2' // the external event - } - }, - A2: { - always: 'A3' - }, - A3: { - always: { - target: 'A4', - guard: stateIn({ B: 'B3' }) - } - }, - A4: {} - } - }, - - B: { - initial: 'B1', - states: { - B1: { - on: { - E: 'B2' - } - }, - B2: { - always: { - target: 'B3', - guard: stateIn({ A: 'A2' }) - } - }, - B3: { - always: { - target: 'B4', - guard: stateIn({ A: 'A3' }) - } - }, - B4: {} - } - } - } - }); - - const actorRef = createActor(machine).start(); - actorRef.send({ type: 'E' }); - - expect(actorRef.getSnapshot().value).toEqual({ A: 'A4', B: 'B4' }); - }); - it('should check for automatic transitions even after microsteps are done', () => { const machine = createMachine({ type: 'parallel', @@ -360,54 +303,6 @@ describe('transient states (eventless transitions)', () => { expect(actorRef.getSnapshot().value).toEqual({ A: 'A2', B: 'B2', C: 'C2' }); }); - it('should check for automatic transitions even after microsteps are done (with `always`)', () => { - const machine = createMachine({ - type: 'parallel', - states: { - A: { - initial: 'A1', - states: { - A1: { - on: { - A: 'A2' - } - }, - A2: { id: 'A2' } - } - }, - B: { - initial: 'B1', - states: { - B1: { - always: { - target: 'B2', - guard: stateIn({ A: 'A2' }) - } - }, - B2: {} - } - }, - C: { - initial: 'C1', - states: { - C1: { - always: { - target: 'C2', - guard: stateIn('#A2') - } - }, - C2: {} - } - } - } - }); - - const actorRef = createActor(machine).start(); - actorRef.send({ type: 'A' }); - - expect(actorRef.getSnapshot().value).toEqual({ A: 'A2', B: 'B2', C: 'C2' }); - }); - it('should determine the resolved initial state from the transient state', () => { expect(createActor(greetingMachine).getSnapshot().value).toEqual('morning'); }); @@ -454,26 +349,6 @@ describe('transient states (eventless transitions)', () => { expect(actorRef.getSnapshot().value).toBe('e'); }); - it('should not select wildcard for eventless transition', () => { - const machine = createMachine({ - initial: 'a', - states: { - a: { - on: { FOO: 'b' } - }, - b: { - on: { '*': 'fail' } - }, - fail: {} - } - }); - - const actorRef = createActor(machine).start(); - actorRef.send({ type: 'FOO' }); - - expect(actorRef.getSnapshot().value).toBe('b'); - }); - it('should not select wildcard for eventless transition', () => { const machine = createMachine({ initial: 'a', @@ -532,41 +407,6 @@ describe('transient states (eventless transitions)', () => { expect(actorRef.getSnapshot().status).toBe('done'); }); - it('should work with transient transition on root (with `always`)', () => { - const machine = createMachine({ - types: {} as { context: { count: number } }, - id: 'machine', - initial: 'first', - context: { count: 0 }, - states: { - first: { - on: { - ADD: { - actions: assign({ count: ({ context }) => context.count + 1 }) - } - } - }, - success: { - type: 'final' - } - }, - - always: [ - { - target: '.success', - guard: ({ context }) => { - return context.count > 0; - } - } - ] - }); - - const actorRef = createActor(machine).start(); - actorRef.send({ type: 'ADD' }); - - expect(actorRef.getSnapshot().status).toBe('done'); - }); - it("shouldn't crash when invoking a machine with initial transient transition depending on custom data", () => { const timerMachine = createMachine({ initial: 'initial', @@ -615,17 +455,13 @@ describe('transient states (eventless transitions)', () => { }); it('should be taken even in absence of other transitions', () => { - let shouldMatch = false; - const machine = createMachine({ initial: 'a', states: { a: { always: { target: 'b', - // TODO: in v5 remove `shouldMatch` and replace this guard with: - // guard: (ctx, ev) => ev.type === 'WHATEVER' - guard: () => shouldMatch + guard: ({ event }) => event.type === 'WHATEVER' } }, b: {} @@ -633,24 +469,19 @@ describe('transient states (eventless transitions)', () => { }); const actorRef = createActor(machine).start(); - shouldMatch = true; actorRef.send({ type: 'WHATEVER' }); expect(actorRef.getSnapshot().value).toBe('b'); }); it('should select subsequent transient transitions even in absence of other transitions', () => { - let shouldMatch = false; - const machine = createMachine({ initial: 'a', states: { a: { always: { target: 'b', - // TODO: in v5 remove `shouldMatch` and replace this guard with: - // guard: (ctx, ev) => ev.type === 'WHATEVER' - guard: () => shouldMatch + guard: ({ event }) => event.type === 'WHATEVER' } }, b: { @@ -665,7 +496,6 @@ describe('transient states (eventless transitions)', () => { const actorRef = createActor(machine).start(); - shouldMatch = true; actorRef.send({ type: 'WHATEVER' }); expect(actorRef.getSnapshot().value).toBe('c');