motia icon indicating copy to clipboard operation
motia copied to clipboard

Create test helpers to test a step in isolation

Open sergiofilhowz opened this issue 2 months ago • 2 comments

The developers want to be able to test a single step in isolation and be able to:

  • Check emitted events
  • Check state changes
  • Check stream changes

Emitted events should not trigger other steps, they're mostly for test assessment.

Example

const handler = (input, { emit }) => {
  if (input.name === 'test') {
     await emit({ topic: 'another-topic', data: { name: input.name });
  }
}

I want to test this step and check if input { name: 'fail' } will trigger an emit and if input { name: 'test' } will trigger an event.

What I expect in this helper functions is a way to create FlowContext.

const mockedContext = tester.createMockedContext()
// ...
mockedContext.emit.toHaveBeenCalledWith({/* ... */}) 

Create examples where we could use to test only event steps directly

Acceptance Criteria

  • [ ] Code must be clean
  • [ ] Code for test should be simple to understand
  • [ ] Test utility should be able to create a FlowContext to mock and validate Streams, State and Emits
  • [ ] New documentation section explaining how to test a step in isolation

sergiofilhowz avatar Oct 17 '25 11:10 sergiofilhowz

Is anyone working on this or can I start it?

Tanmay-008 avatar Oct 19 '25 06:10 Tanmay-008

This is cool! I am on it

riturajFi avatar Oct 23 '25 14:10 riturajFi