Testing Projectors
Projectors produce external state, or state that’s designed to be consumed by third parties. Since this state is part of the public API of the system, you need to write tests that assert that the shape of the projections matches what you expect.
It’s tempting to have your projector write the projected state directly to the external data store. When building examples and prototypes, it’s often much easier to simply write the projection out during processing. But when it comes time to test, such a design pattern makes the projector “effectful.” Writing the data ends up being a side effect of processing events.
It’s much more testable (and arguably cleaner) if the projectors return the new projection as a result of processing ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access