motia
motia copied to clipboard
Create test helpers to test a step in isolation
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
Is anyone working on this or can I start it?
This is cool! I am on it