Skip to content

Validation

Ricardo Canastro edited this page Apr 1, 2022 · 1 revision

In order to help you identify some possible issues with your State Machine definition, Automata provides a validate method that you can use in a unit test.

Currently Automata provides a simple set of validations:

  • State machine includes at least one atomic / final state
  • A State node does not include two transitions for the same event without condition
  • A State node does not include a onDone callback that does not gather the conditions to ever be called.

Here is an example on how you can use this feature:

test('should be a valid state machine', () {
  final machine = StateMachine.create(
    (g) => g
      ..initial<_StateA>()
      ..state<_StateA>(
        builder: (b) => b
          ..state<_StateB>(type: StateNodeType.terminal)
          ..state<_StateC>(),
      ),
  );

  expect(
    () => machine.validate(),
    returnsNormally,
  );
});
Clone this wiki locally