Improve frontend tests

This commit is contained in:
Juho Teperi 2018-08-22 10:47:04 +03:00
parent c1d8ec99d8
commit c11d21d9ec

View file

@ -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))))
(testing "console warning about missing route"
(is (= [{:type :warn (is (= [{:type :warn
:message ["missing route" ::asd]}] :message ["missing route" ::asd]}]
(:messages (:messages
(capture-console (capture-console
(fn [] (fn []
(rf/match-by-name! router ::asd)))))))) (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,6 +67,7 @@
(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}))))
(testing "query param is read"
(is (= (r/map->Match (is (= (r/map->Match
{:template "/:id" {:template "/:id"
:path-params {:id "5"} :path-params {:id "5"}
@ -75,8 +78,18 @@
(m (rf/match-by-path router "/5?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}))))
(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 (is (= [{:type :warn
:message ["missing path-params for route" ::foo :message ["missing path-params for route" ::foo
{:template "/:id" {:template "/:id"
@ -86,4 +99,4 @@
(:messages (:messages
(capture-console (capture-console
(fn [] (fn []
(rf/match-by-name! router ::foo {}))))))))) (rf/match-by-name! router ::foo {}))))))))))