mirror of
https://github.com/metosin/reitit.git
synced 2025-12-18 00:41:12 +00:00
Run history tests only on browser
This commit is contained in:
parent
245902bd4d
commit
06b641398a
1 changed files with 32 additions and 28 deletions
|
|
@ -3,42 +3,46 @@
|
||||||
[reitit.core :as r]
|
[reitit.core :as r]
|
||||||
[reitit.frontend.history :as rfh]))
|
[reitit.frontend.history :as rfh]))
|
||||||
|
|
||||||
|
(def browser (exists? js/window))
|
||||||
|
|
||||||
(deftest fragment-history-test
|
(deftest fragment-history-test
|
||||||
(let [router (r/router ["/"
|
(when browser
|
||||||
|
(let [router (r/router ["/"
|
||||||
["" ::frontpage]
|
["" ::frontpage]
|
||||||
["foo" ::foo]
|
["foo" ::foo]
|
||||||
["bar/:id" ::bar]])
|
["bar/:id" ::bar]])
|
||||||
history (rfh/start! router
|
history (rfh/start! router
|
||||||
(fn [_])
|
(fn [_])
|
||||||
{:use-fragment true
|
{:use-fragment true
|
||||||
:path-prefix "/"})]
|
:path-prefix "/"})]
|
||||||
|
|
||||||
(testing "creating urls"
|
(testing "creating urls"
|
||||||
(is (= "#/foo"
|
(is (= "#/foo"
|
||||||
(rfh/href history ::foo)))
|
(rfh/href history ::foo)))
|
||||||
(is (= "#/bar/5"
|
(is (= "#/bar/5"
|
||||||
(rfh/href history ::bar {:id 5})))
|
(rfh/href history ::bar {:id 5})))
|
||||||
(is (= "#/bar/5?q=x"
|
(is (= "#/bar/5?q=x"
|
||||||
(rfh/href history ::bar {:id 5} {:q "x"})))
|
(rfh/href history ::bar {:id 5} {:q "x"})))
|
||||||
(is (= nil
|
(is (= nil
|
||||||
(rfh/href history ::asd))))))
|
(rfh/href history ::asd)))))))
|
||||||
|
|
||||||
(deftest html5-history-test
|
(deftest html5-history-test
|
||||||
(let [router (r/router ["/"
|
(when browser
|
||||||
|
(let [router (r/router ["/"
|
||||||
["" ::frontpage]
|
["" ::frontpage]
|
||||||
["foo" ::foo]
|
["foo" ::foo]
|
||||||
["bar/:id" ::bar]])
|
["bar/:id" ::bar]])
|
||||||
history (rfh/start! router
|
history (rfh/start! router
|
||||||
(fn [_])
|
(fn [_])
|
||||||
{:use-fragment false
|
{:use-fragment false
|
||||||
:path-prefix "/"})]
|
:path-prefix "/"})]
|
||||||
|
|
||||||
(testing "creating urls"
|
(testing "creating urls"
|
||||||
(is (= "/foo"
|
(is (= "/foo"
|
||||||
(rfh/href history ::foo)))
|
(rfh/href history ::foo)))
|
||||||
(is (= "/bar/5"
|
(is (= "/bar/5"
|
||||||
(rfh/href history ::bar {:id 5})))
|
(rfh/href history ::bar {:id 5})))
|
||||||
(is (= "/bar/5?q=x"
|
(is (= "/bar/5?q=x"
|
||||||
(rfh/href history ::bar {:id 5} {:q "x"})))
|
(rfh/href history ::bar {:id 5} {:q "x"})))
|
||||||
(is (= nil
|
(is (= nil
|
||||||
(rfh/href history ::asd))))))
|
(rfh/href history ::asd)))))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue