diff --git a/tests/api.go b/tests/api.go index 27d23ec1..a3d0dc32 100644 --- a/tests/api.go +++ b/tests/api.go @@ -13,6 +13,7 @@ import ( "github.com/labstack/echo/v5" "github.com/pocketbase/pocketbase/apis" + "github.com/pocketbase/pocketbase/core" ) // ApiScenario defines a single api request test case/scenario. @@ -55,6 +56,8 @@ func (scenario *ApiScenario) test(t *testing.T) { var testApp *TestApp var testAppErr error if scenario.TestAppFactory != nil { + // @todo consider passing the testing instance to the factory and maybe remove the error from the declaration + // (see https://github.com/pocketbase/pocketbase/discussions/3025) testApp, testAppErr = scenario.TestAppFactory() } else { testApp, testAppErr = NewTestApp() @@ -69,6 +72,12 @@ func (scenario *ApiScenario) test(t *testing.T) { t.Fatal(err) } + // manually trigger the serve event to ensure that custom app routes and middlewares are registered + testApp.OnBeforeServe().Trigger(&core.ServeEvent{ + App: testApp, + Router: e, + }) + if scenario.BeforeTestFunc != nil { scenario.BeforeTestFunc(t, testApp, e) }