mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 00:11: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"
|
||||
(r/match->path (rf/match-by-name router ::foo))))
|
||||
|
||||
(testing "console warning about missing route"
|
||||
(is (= [{:type :warn
|
||||
:message ["missing route" ::asd]}]
|
||||
(:messages
|
||||
(capture-console
|
||||
(fn []
|
||||
(rf/match-by-name! router ::asd))))))))
|
||||
(rf/match-by-name! router ::asd)))))))))
|
||||
|
||||
(testing "schema coercion"
|
||||
(let [router (r/router ["/"
|
||||
|
|
@ -54,6 +55,7 @@
|
|||
:query {(s/optional-key :mode) s/Keyword}}}]]
|
||||
{:compile rc/compile-request-coercers
|
||||
:data {:coercion rsc/coercion}})]
|
||||
|
||||
(is (= (r/map->Match
|
||||
{:template "/:id"
|
||||
:path-params {:id "5"}
|
||||
|
|
@ -65,6 +67,7 @@
|
|||
(is (= "/5"
|
||||
(r/match->path (rf/match-by-name router ::foo {:id 5}))))
|
||||
|
||||
(testing "query param is read"
|
||||
(is (= (r/map->Match
|
||||
{:template "/:id"
|
||||
:path-params {:id "5"}
|
||||
|
|
@ -75,8 +78,18 @@
|
|||
(m (rf/match-by-path router "/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}))))
|
||||
|
||||
(testing "fragment is ignored"
|
||||
(is (= (r/map->Match
|
||||
{:template "/:id"
|
||||
:path-params {:id "5"}
|
||||
:path "/5"
|
||||
:parameters {:path {:id 5}
|
||||
:query {:mode :foo}}})
|
||||
(m (rf/match-by-path router "/5?mode=foo#fragment")))))
|
||||
|
||||
(testing "console warning about missing params"
|
||||
(is (= [{:type :warn
|
||||
:message ["missing path-params for route" ::foo
|
||||
{:template "/:id"
|
||||
|
|
@ -86,4 +99,4 @@
|
|||
(:messages
|
||||
(capture-console
|
||||
(fn []
|
||||
(rf/match-by-name! router ::foo {})))))))))
|
||||
(rf/match-by-name! router ::foo {}))))))))))
|
||||
|
|
|
|||
Loading…
Reference in a new issue