From 0c1694c94762779fa27368e5beab4cb877be1faf Mon Sep 17 00:00:00 2001 From: Rene Nochebuena Date: Sun, 13 Apr 2025 01:33:25 -0600 Subject: [PATCH] Add test for DispatchEvent with error handling This commit introduces a new test, Test_DispatchEventWithError, to verify error handling when dispatching events. It ensures that the dispatcher properly returns an error when an event handler triggers one. --- dispatcher_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/dispatcher_test.go b/dispatcher_test.go index b266481..fd486ff 100644 --- a/dispatcher_test.go +++ b/dispatcher_test.go @@ -136,6 +136,17 @@ func Test_UnknownEvent(t *testing.T) { } } +func Test_DispatchEventWithError(t *testing.T) { + d := NewDispatcher() + d.RegisterCommandHandler(testCommand{}, &testCommandHandler{}) + d.RegisterEventHandler(testEvent{}, &testErrorEventHandler{}) + + err := d.DispatchEvent(context.Background(), testEvent{}) + if err == nil { + t.Fatal("expected error") + } +} + func Test_Error(t *testing.T) { d := NewDispatcher() d.RegisterCommandHandler(testCommand{}, &testErrorHandler{})