mirror of https://github.com/status-im/reagent.git
Remove found-in test checker, use = for better errors
This commit is contained in:
parent
f5bfa6160e
commit
c2bf3c0407
|
@ -5,7 +5,7 @@
|
||||||
[reagent.debug :as debug :refer-macros [dev?]]
|
[reagent.debug :as debug :refer-macros [dev?]]
|
||||||
[reagent.core :as r]
|
[reagent.core :as r]
|
||||||
[reagent.dom.server :as server]
|
[reagent.dom.server :as server]
|
||||||
[reagenttest.utils :as u :refer [with-mounted-component found-in]]
|
[reagenttest.utils :as u :refer [with-mounted-component]]
|
||||||
[clojure.string :as string]
|
[clojure.string :as string]
|
||||||
[goog.string :as gstr]
|
[goog.string :as gstr]
|
||||||
[goog.object :as gobj]
|
[goog.object :as gobj]
|
||||||
|
@ -51,7 +51,7 @@
|
||||||
(with-mounted-component [really-simple nil nil]
|
(with-mounted-component [really-simple nil nil]
|
||||||
(fn [c div]
|
(fn [c div]
|
||||||
(swap! ran inc)
|
(swap! ran inc)
|
||||||
(is (found-in #"div in really-simple" div))
|
(is (= "div in really-simple" (.-innerText div)))
|
||||||
(r/flush)
|
(r/flush)
|
||||||
(is (= 2 @ran))
|
(is (= 2 @ran))
|
||||||
(r/force-update-all)
|
(r/force-update-all)
|
||||||
|
@ -75,7 +75,7 @@
|
||||||
(with-mounted-component [comp {:foo "you"} 1]
|
(with-mounted-component [comp {:foo "you"} 1]
|
||||||
(fn [C div]
|
(fn [C div]
|
||||||
(swap! ran inc)
|
(swap! ran inc)
|
||||||
(is (found-in #"hi you" div))))
|
(is (= "hi you." (.-innerText div)))))
|
||||||
(is (= 3 @ran)))))
|
(is (= 3 @ran)))))
|
||||||
|
|
||||||
(deftest test-state-change
|
(deftest test-state-change
|
||||||
|
@ -93,17 +93,17 @@
|
||||||
(with-mounted-component [comp]
|
(with-mounted-component [comp]
|
||||||
(fn [C div]
|
(fn [C div]
|
||||||
(swap! ran inc)
|
(swap! ran inc)
|
||||||
(is (found-in #"hi initial" div))
|
(is (= "hi initial" (.-innerText div)))
|
||||||
|
|
||||||
(r/replace-state @self {:foo "there"})
|
(r/replace-state @self {:foo "there"})
|
||||||
(r/state @self)
|
(r/state @self)
|
||||||
|
|
||||||
(rflush)
|
(rflush)
|
||||||
(is (found-in #"hi there" div))
|
(is (= "hi there" (.-innerText div)))
|
||||||
|
|
||||||
(r/set-state @self {:foo "you"})
|
(r/set-state @self {:foo "you"})
|
||||||
(rflush)
|
(rflush)
|
||||||
(is (found-in #"hi you" div))))
|
(is (= "hi you" (.-innerText div)))))
|
||||||
(is (= 4 @ran)))))
|
(is (= 4 @ran)))))
|
||||||
|
|
||||||
(deftest test-ratom-change
|
(deftest test-ratom-change
|
||||||
|
@ -116,12 +116,12 @@
|
||||||
v1 (reaction (swap! v1-ran inc) @val)
|
v1 (reaction (swap! v1-ran inc) @val)
|
||||||
comp (fn []
|
comp (fn []
|
||||||
(swap! ran inc)
|
(swap! ran inc)
|
||||||
[:div (str "val " @v1 @val @secval)])]
|
[:div (str "val " @v1 " " @val " " @secval)])]
|
||||||
(with-mounted-component [comp]
|
(with-mounted-component [comp]
|
||||||
(fn [C div]
|
(fn [C div]
|
||||||
(r/flush)
|
(r/flush)
|
||||||
(is (not= runs (running)))
|
(is (not= runs (running)))
|
||||||
(is (found-in #"val 0" div))
|
(is (= "val 0 0 0" (.-innerText div)))
|
||||||
(is (= 1 @ran))
|
(is (= 1 @ran))
|
||||||
|
|
||||||
(reset! secval 1)
|
(reset! secval 1)
|
||||||
|
@ -132,7 +132,7 @@
|
||||||
(is (= 1 @ran))
|
(is (= 1 @ran))
|
||||||
(is (= 1 @v1-ran))
|
(is (= 1 @v1-ran))
|
||||||
(r/flush)
|
(r/flush)
|
||||||
(is (found-in #"val 1" div))
|
(is (= "val 1 1 0" (.-innerText div)))
|
||||||
(is (= 2 @ran) "ran once more")
|
(is (= 2 @ran) "ran once more")
|
||||||
(is (= 2 @v1-ran))
|
(is (= 2 @v1-ran))
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@
|
||||||
(is (= 2 @v1-ran))
|
(is (= 2 @v1-ran))
|
||||||
(r/flush)
|
(r/flush)
|
||||||
(is (= 2 @v1-ran))
|
(is (= 2 @v1-ran))
|
||||||
(is (found-in #"val 1" div))
|
(is (= "val 1 1 0" (.-innerText div)))
|
||||||
(is (= 2 @ran) "did not run")))
|
(is (= 2 @ran) "did not run")))
|
||||||
(is (= runs (running)))
|
(is (= runs (running)))
|
||||||
(is (= 2 @ran)))))
|
(is (= 2 @ran)))))
|
||||||
|
@ -193,7 +193,7 @@
|
||||||
(with-mounted-component [really-simple nil nil]
|
(with-mounted-component [really-simple nil nil]
|
||||||
(fn [c div]
|
(fn [c div]
|
||||||
(swap! ran inc)
|
(swap! ran inc)
|
||||||
(is (found-in #"this is foobar" div))))
|
(is (= "this is foobar" (.-innerText div)))))
|
||||||
(is (= 2 @ran)))))
|
(is (= 2 @ran)))))
|
||||||
|
|
||||||
(deftest shoud-update-test
|
(deftest shoud-update-test
|
||||||
|
@ -215,7 +215,7 @@
|
||||||
(fn [c div]
|
(fn [c div]
|
||||||
(rflush)
|
(rflush)
|
||||||
(is (= @child-ran 1))
|
(is (= @child-ran 1))
|
||||||
(is (found-in #"child-foo" div))
|
(is (= "child-foo" (.-innerText div)))
|
||||||
(reset! child-props {:style {:display :none}})
|
(reset! child-props {:style {:display :none}})
|
||||||
(rflush)
|
(rflush)
|
||||||
(is (= @child-ran 2))
|
(is (= @child-ran 2))
|
||||||
|
@ -257,11 +257,11 @@
|
||||||
(with-mounted-component [really-simple nil nil]
|
(with-mounted-component [really-simple nil nil]
|
||||||
(fn [c div]
|
(fn [c div]
|
||||||
(is (= 1 @ran))
|
(is (= 1 @ran))
|
||||||
(is (found-in #"state=0" div))
|
(is (= "state=0" (.-innerText div)))
|
||||||
(reset! state 1)
|
(reset! state 1)
|
||||||
(rflush)
|
(rflush)
|
||||||
(is (= 2 @ran))
|
(is (= 2 @ran))
|
||||||
(is (found-in #"state=3" div))))
|
(is (= "state=3" (.-innerText div)))))
|
||||||
(is (= 2 @ran)))))
|
(is (= 2 @ran)))))
|
||||||
|
|
||||||
(defn as-string [comp]
|
(defn as-string [comp]
|
||||||
|
@ -389,13 +389,13 @@
|
||||||
(with-mounted-component [parent]
|
(with-mounted-component [parent]
|
||||||
(fn [C div]
|
(fn [C div]
|
||||||
(swap! ran inc)
|
(swap! ran inc)
|
||||||
(is (found-in #"hi you" div))
|
(is (= "hi you." (.-innerText div)))
|
||||||
(is (= 1 @top-ran))
|
(is (= 1 @top-ran))
|
||||||
(is (= 3 @ran))
|
(is (= 3 @ran))
|
||||||
|
|
||||||
(swap! prop assoc :foo "me")
|
(swap! prop assoc :foo "me")
|
||||||
(r/flush)
|
(r/flush)
|
||||||
(is (found-in #"hi me" div))
|
(is (= "hi me." (.-innerText div)))
|
||||||
(is (= 1 @top-ran))
|
(is (= 1 @top-ran))
|
||||||
(is (= 4 @ran)))))))
|
(is (= 4 @ran)))))))
|
||||||
|
|
||||||
|
@ -417,13 +417,13 @@
|
||||||
(with-mounted-component [parent]
|
(with-mounted-component [parent]
|
||||||
(fn [C div]
|
(fn [C div]
|
||||||
(swap! ran inc)
|
(swap! ran inc)
|
||||||
(is (found-in #"hi you" div))
|
(is (= "hi you." (.-innerText div)))
|
||||||
(is (= 1 @top-ran))
|
(is (= 1 @top-ran))
|
||||||
(is (= 3 @ran))
|
(is (= 3 @ran))
|
||||||
|
|
||||||
(swap! prop assoc :foo "me")
|
(swap! prop assoc :foo "me")
|
||||||
(r/flush)
|
(r/flush)
|
||||||
(is (found-in #"hi me" div))
|
(is (= "hi me." (.-innerText div)))
|
||||||
(is (= 1 @top-ran))
|
(is (= 1 @top-ran))
|
||||||
(is (= 4 @ran)))))))
|
(is (= 4 @ran)))))))
|
||||||
|
|
||||||
|
@ -1312,10 +1312,10 @@
|
||||||
[pure-component {:value @prop}])]
|
[pure-component {:value @prop}])]
|
||||||
(with-mounted-component [component]
|
(with-mounted-component [component]
|
||||||
(fn [c div]
|
(fn [c div]
|
||||||
(is (found-in #"Value foo" div))
|
(is (= "Value foo" (.-innerText div)))
|
||||||
(swap! prop inc)
|
(swap! prop inc)
|
||||||
(r/flush)
|
(r/flush)
|
||||||
(is (found-in #"Value foo foo" div)))))))
|
(is (= "Value foo foo" (.-innerText div))))))))
|
||||||
|
|
||||||
(deftest get-derived-state-from-error-test
|
(deftest get-derived-state-from-error-test
|
||||||
(when isClient
|
(when isClient
|
||||||
|
@ -1338,10 +1338,10 @@
|
||||||
(wrap-capture-console-error
|
(wrap-capture-console-error
|
||||||
#(with-mounted-component [component [bad-component]]
|
#(with-mounted-component [component [bad-component]]
|
||||||
(fn [c div]
|
(fn [c div]
|
||||||
(is (found-in #"Ok" div))
|
(is (= "Ok" (.-innerText div)))
|
||||||
(swap! prop inc)
|
(swap! prop inc)
|
||||||
(r/flush)
|
(r/flush)
|
||||||
(is (found-in #"Error" div)))))))))
|
(is (= "Error" (.-innerText div))))))))))
|
||||||
|
|
||||||
(deftest get-snapshot-before-update-test
|
(deftest get-snapshot-before-update-test
|
||||||
(when isClient
|
(when isClient
|
||||||
|
@ -1365,7 +1365,7 @@
|
||||||
(fn [c div]
|
(fn [c div]
|
||||||
;; Attach to DOM to get real height value
|
;; Attach to DOM to get real height value
|
||||||
(.appendChild js/document.body div)
|
(.appendChild js/document.body div)
|
||||||
(is (found-in #"foo" div))
|
(is (= "foo" (.-innerText div)))
|
||||||
(swap! prop inc)
|
(swap! prop inc)
|
||||||
(r/flush)
|
(r/flush)
|
||||||
(is (= {:height 20} @did-update))
|
(is (= {:height 20} @did-update))
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
(ns reagenttest.testwrap
|
(ns reagenttest.testwrap
|
||||||
(:require [clojure.test :as t :refer-macros [is deftest]]
|
(:require [clojure.test :as t :refer-macros [is deftest]]
|
||||||
[reagent.core :as r]
|
[reagent.core :as r]
|
||||||
[reagenttest.utils :as u :refer [with-mounted-component found-in]]))
|
[reagenttest.utils :as u :refer [with-mounted-component]]))
|
||||||
|
|
||||||
(deftest test-wrap-basic
|
(deftest test-wrap-basic
|
||||||
(let [state (r/atom {:foo 1})
|
(let [state (r/atom {:foo 1})
|
||||||
|
@ -112,19 +112,19 @@
|
||||||
(fn [c div done]
|
(fn [c div done]
|
||||||
(u/run-fns-after-render
|
(u/run-fns-after-render
|
||||||
(fn []
|
(fn []
|
||||||
(is (found-in #"value:1:" div))
|
(is (= "value:1:" (.-innerText div)))
|
||||||
(is (= @ran 1))
|
(is (= @ran 1))
|
||||||
|
|
||||||
(reset! @grand-state {:foobar 2}))
|
(reset! @grand-state {:foobar 2}))
|
||||||
(fn []
|
(fn []
|
||||||
(is (= @state {:foo {:bar {:foobar 2}}}))
|
(is (= @state {:foo {:bar {:foobar 2}}}))
|
||||||
(is (= @ran 2))
|
(is (= @ran 2))
|
||||||
(is (found-in #"value:2:" div))
|
(is (= "value:2:" (.-innerText div)))
|
||||||
|
|
||||||
(swap! state update-in [:foo :bar] assoc :foobar 3))
|
(swap! state update-in [:foo :bar] assoc :foobar 3))
|
||||||
(fn []
|
(fn []
|
||||||
(is (= @ran 3))
|
(is (= @ran 3))
|
||||||
(is (found-in #"value:3:" div))
|
(is (= "value:3:" (.-innerText div)))
|
||||||
(reset! state {:foo {:bar {:foobar 3}}
|
(reset! state {:foo {:bar {:foobar 3}}
|
||||||
:foo1 {}}))
|
:foo1 {}}))
|
||||||
(fn []
|
(fn []
|
||||||
|
@ -136,23 +136,23 @@
|
||||||
(reset! state {:foo {:bar {:foobar 2}}
|
(reset! state {:foo {:bar {:foobar 2}}
|
||||||
:foo2 {}}))
|
:foo2 {}}))
|
||||||
(fn []
|
(fn []
|
||||||
(is (found-in #"value:2:" div))
|
(is (= "value:2:" (.-innerText div)))
|
||||||
(is (= @ran 4))
|
(is (= @ran 4))
|
||||||
|
|
||||||
(reset! @grand-state {:foobar 2}))
|
(reset! @grand-state {:foobar 2}))
|
||||||
(fn []
|
(fn []
|
||||||
(is (found-in #"value:2:" div))
|
(is (= "value:2:" (.-innerText div)))
|
||||||
(is (= @ran 5))
|
(is (= @ran 5))
|
||||||
|
|
||||||
(reset! state {:foo {:bar {:foobar 4}}})
|
(reset! state {:foo {:bar {:foobar 4}}})
|
||||||
(reset! @grand-state {:foobar 4}))
|
(reset! @grand-state {:foobar 4}))
|
||||||
(fn []
|
(fn []
|
||||||
(is (found-in #"value:4:" div))
|
(is (= "value:4:" (.-innerText div)))
|
||||||
(is (= @ran 6))
|
(is (= @ran 6))
|
||||||
|
|
||||||
(reset! @grand-state {:foobar 4}))
|
(reset! @grand-state {:foobar 4}))
|
||||||
(fn []
|
(fn []
|
||||||
(is (found-in #"value:4:" div))
|
(is (= "value:4:" (.-innerText div)))
|
||||||
(is (= @ran 7)))
|
(is (= @ran 7)))
|
||||||
done)))))))
|
done)))))))
|
||||||
|
|
||||||
|
|
|
@ -27,11 +27,3 @@
|
||||||
(f)
|
(f)
|
||||||
(cb)))))
|
(cb)))))
|
||||||
(reverse fs))))
|
(reverse fs))))
|
||||||
|
|
||||||
(defn found-in [re div]
|
|
||||||
(let [res (.-innerHTML div)]
|
|
||||||
(if (re-find re res)
|
|
||||||
true
|
|
||||||
(do (println "Not found: " res)
|
|
||||||
false))))
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue