feat: reitit.core/Expand for Vars

This commit is contained in:
Joel Kaasinen 2024-03-15 09:21:51 +02:00
parent 659e96e780
commit 5d30a73bad
2 changed files with 12 additions and 1 deletions

View file

@ -28,6 +28,10 @@
:cljs function)
(expand [this _] {:handler this})
#?(:clj clojure.lang.Var
:cljs cljs.core.Var)
(expand [this _] {:handler this})
nil
(expand [_ _]))

View file

@ -6,6 +6,9 @@
(:import (clojure.lang ExceptionInfo)
(reitit.core Router))))
(defn- var-handler [& _]
"var-handler")
(deftest reitit-test
(testing "routers handling wildcard paths"
@ -245,7 +248,11 @@
(let [router (r/router ["/ping" (constantly "ok")])
{:keys [result]} (r/match-by-path router "/ping")]
(is result)
(is (= "ok" (result))))))
(is (= "ok" (result))))
(testing "var handler gets expanded"
(let [router (r/router ["/ping" #'var-handler])
{:keys [result]} (r/match-by-path router "/ping")]
(is (= #'var-handler result))))))
(testing "custom router"
(let [router (r/router ["/ping"] {:router (fn [_ _]