mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 08:21:11 +00:00
Improve frontend tests
This commit is contained in:
parent
c1d8ec99d8
commit
c11d21d9ec
1 changed files with 39 additions and 26 deletions
|
|
@ -40,12 +40,13 @@
|
||||||
(is (= "/foo"
|
(is (= "/foo"
|
||||||
(r/match->path (rf/match-by-name router ::foo))))
|
(r/match->path (rf/match-by-name router ::foo))))
|
||||||
|
|
||||||
(is (= [{:type :warn
|
(testing "console warning about missing route"
|
||||||
:message ["missing route" ::asd]}]
|
(is (= [{:type :warn
|
||||||
(:messages
|
:message ["missing route" ::asd]}]
|
||||||
(capture-console
|
(:messages
|
||||||
(fn []
|
(capture-console
|
||||||
(rf/match-by-name! router ::asd))))))))
|
(fn []
|
||||||
|
(rf/match-by-name! router ::asd)))))))))
|
||||||
|
|
||||||
(testing "schema coercion"
|
(testing "schema coercion"
|
||||||
(let [router (r/router ["/"
|
(let [router (r/router ["/"
|
||||||
|
|
@ -54,6 +55,7 @@
|
||||||
:query {(s/optional-key :mode) s/Keyword}}}]]
|
:query {(s/optional-key :mode) s/Keyword}}}]]
|
||||||
{:compile rc/compile-request-coercers
|
{:compile rc/compile-request-coercers
|
||||||
:data {:coercion rsc/coercion}})]
|
:data {:coercion rsc/coercion}})]
|
||||||
|
|
||||||
(is (= (r/map->Match
|
(is (= (r/map->Match
|
||||||
{:template "/:id"
|
{:template "/:id"
|
||||||
:path-params {:id "5"}
|
:path-params {:id "5"}
|
||||||
|
|
@ -65,25 +67,36 @@
|
||||||
(is (= "/5"
|
(is (= "/5"
|
||||||
(r/match->path (rf/match-by-name router ::foo {:id 5}))))
|
(r/match->path (rf/match-by-name router ::foo {:id 5}))))
|
||||||
|
|
||||||
(is (= (r/map->Match
|
(testing "query param is read"
|
||||||
{:template "/:id"
|
(is (= (r/map->Match
|
||||||
:path-params {:id "5"}
|
{:template "/:id"
|
||||||
;; Note: query not included in path
|
:path-params {:id "5"}
|
||||||
:path "/5"
|
;; Note: query not included in path
|
||||||
:parameters {:path {:id 5}
|
:path "/5"
|
||||||
:query {:mode :foo}}})
|
:parameters {:path {:id 5}
|
||||||
(m (rf/match-by-path router "/5?mode=foo"))))
|
:query {:mode :foo}}})
|
||||||
|
(m (rf/match-by-path router "/5?mode=foo"))))
|
||||||
|
|
||||||
(is (= "/5?mode=foo"
|
(is (= "/5?mode=foo"
|
||||||
(r/match->path (rf/match-by-name router ::foo {:id 5}) {:mode :foo})))
|
(r/match->path (rf/match-by-name router ::foo {:id 5}) {:mode :foo}))))
|
||||||
|
|
||||||
(is (= [{:type :warn
|
(testing "fragment is ignored"
|
||||||
:message ["missing path-params for route" ::foo
|
(is (= (r/map->Match
|
||||||
{:template "/:id"
|
{:template "/:id"
|
||||||
:missing #{:id}
|
:path-params {:id "5"}
|
||||||
:required #{:id}
|
:path "/5"
|
||||||
:path-params {}}]}]
|
:parameters {:path {:id 5}
|
||||||
(:messages
|
:query {:mode :foo}}})
|
||||||
(capture-console
|
(m (rf/match-by-path router "/5?mode=foo#fragment")))))
|
||||||
(fn []
|
|
||||||
(rf/match-by-name! router ::foo {})))))))))
|
(testing "console warning about missing params"
|
||||||
|
(is (= [{:type :warn
|
||||||
|
:message ["missing path-params for route" ::foo
|
||||||
|
{:template "/:id"
|
||||||
|
:missing #{:id}
|
||||||
|
:required #{:id}
|
||||||
|
:path-params {}}]}]
|
||||||
|
(:messages
|
||||||
|
(capture-console
|
||||||
|
(fn []
|
||||||
|
(rf/match-by-name! router ::foo {}))))))))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue