From 3218ca46cbbd52a9ee500446f1fcfb30363b93cb Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Fri, 20 Aug 2021 11:11:06 +0300 Subject: [PATCH] chore: change test for actions --- fsm.test.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/fsm.test.ts b/fsm.test.ts index 6e2a2ef..bdac37c 100644 --- a/fsm.test.ts +++ b/fsm.test.ts @@ -83,15 +83,20 @@ Deno.test("should change state", async function () { }); Deno.test("should trigger state actions", async function () { + const triggeredTimes = { + beforeExit: 0, + onEntry: 0, + }; + const sm = new fsm.StateMachineBuilder() .withStates( Object.values(ProjectStatus), { - onEntry(fromState, toState) { - console.log(`changing from ${fromState} to ${toState}`); + onEntry() { + triggeredTimes.onEntry += 1; }, - beforeExit(fromState, toState) { - console.log(`before changing from ${fromState} to ${toState}`); + beforeExit() { + triggeredTimes.beforeExit += 1; return true; }, }, @@ -104,12 +109,15 @@ Deno.test("should trigger state actions", async function () { const [, active, completed, archived] = sm[fsm._states]; + assertEquals(triggeredTimes, { beforeExit: 0, onEntry: 0 }); assertEquals(sm.allowedTransitionStates(), [active, archived]); await sm.changeState(ProjectStatus.Active); + assertEquals(triggeredTimes, { beforeExit: 1, onEntry: 1 }); assertEquals(sm.allowedTransitionStates(), [completed]); await sm.changeState(ProjectStatus.Completed); + assertEquals(triggeredTimes, { beforeExit: 2, onEntry: 2 }); assertEquals(sm.allowedTransitionStates(), []); });