Remove found-in test checker, use = for better errors

This commit is contained in:
Juho Teperi 2020-02-03 17:34:31 +02:00
parent f5bfa6160e
commit c2bf3c0407
3 changed files with 31 additions and 39 deletions

View File

@ -5,7 +5,7 @@
[reagent.debug :as debug :refer-macros [dev?]]
[reagent.core :as r]
[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]
[goog.string :as gstr]
[goog.object :as gobj]
@ -51,7 +51,7 @@
(with-mounted-component [really-simple nil nil]
(fn [c div]
(swap! ran inc)
(is (found-in #"div in really-simple" div))
(is (= "div in really-simple" (.-innerText div)))
(r/flush)
(is (= 2 @ran))
(r/force-update-all)
@ -75,7 +75,7 @@
(with-mounted-component [comp {:foo "you"} 1]
(fn [C div]
(swap! ran inc)
(is (found-in #"hi you" div))))
(is (= "hi you." (.-innerText div)))))
(is (= 3 @ran)))))
(deftest test-state-change
@ -93,17 +93,17 @@
(with-mounted-component [comp]
(fn [C div]
(swap! ran inc)
(is (found-in #"hi initial" div))
(is (= "hi initial" (.-innerText div)))
(r/replace-state @self {:foo "there"})
(r/state @self)
(rflush)
(is (found-in #"hi there" div))
(is (= "hi there" (.-innerText div)))
(r/set-state @self {:foo "you"})
(rflush)
(is (found-in #"hi you" div))))
(is (= "hi you" (.-innerText div)))))
(is (= 4 @ran)))))
(deftest test-ratom-change
@ -116,12 +116,12 @@
v1 (reaction (swap! v1-ran inc) @val)
comp (fn []
(swap! ran inc)
[:div (str "val " @v1 @val @secval)])]
[:div (str "val " @v1 " " @val " " @secval)])]
(with-mounted-component [comp]
(fn [C div]
(r/flush)
(is (not= runs (running)))
(is (found-in #"val 0" div))
(is (= "val 0 0 0" (.-innerText div)))
(is (= 1 @ran))
(reset! secval 1)
@ -132,7 +132,7 @@
(is (= 1 @ran))
(is (= 1 @v1-ran))
(r/flush)
(is (found-in #"val 1" div))
(is (= "val 1 1 0" (.-innerText div)))
(is (= 2 @ran) "ran once more")
(is (= 2 @v1-ran))
@ -141,7 +141,7 @@
(is (= 2 @v1-ran))
(r/flush)
(is (= 2 @v1-ran))
(is (found-in #"val 1" div))
(is (= "val 1 1 0" (.-innerText div)))
(is (= 2 @ran) "did not run")))
(is (= runs (running)))
(is (= 2 @ran)))))
@ -193,7 +193,7 @@
(with-mounted-component [really-simple nil nil]
(fn [c div]
(swap! ran inc)
(is (found-in #"this is foobar" div))))
(is (= "this is foobar" (.-innerText div)))))
(is (= 2 @ran)))))
(deftest shoud-update-test
@ -215,7 +215,7 @@
(fn [c div]
(rflush)
(is (= @child-ran 1))
(is (found-in #"child-foo" div))
(is (= "child-foo" (.-innerText div)))
(reset! child-props {:style {:display :none}})
(rflush)
(is (= @child-ran 2))
@ -257,11 +257,11 @@
(with-mounted-component [really-simple nil nil]
(fn [c div]
(is (= 1 @ran))
(is (found-in #"state=0" div))
(is (= "state=0" (.-innerText div)))
(reset! state 1)
(rflush)
(is (= 2 @ran))
(is (found-in #"state=3" div))))
(is (= "state=3" (.-innerText div)))))
(is (= 2 @ran)))))
(defn as-string [comp]
@ -389,13 +389,13 @@
(with-mounted-component [parent]
(fn [C div]
(swap! ran inc)
(is (found-in #"hi you" div))
(is (= "hi you." (.-innerText div)))
(is (= 1 @top-ran))
(is (= 3 @ran))
(swap! prop assoc :foo "me")
(r/flush)
(is (found-in #"hi me" div))
(is (= "hi me." (.-innerText div)))
(is (= 1 @top-ran))
(is (= 4 @ran)))))))
@ -417,13 +417,13 @@
(with-mounted-component [parent]
(fn [C div]
(swap! ran inc)
(is (found-in #"hi you" div))
(is (= "hi you." (.-innerText div)))
(is (= 1 @top-ran))
(is (= 3 @ran))
(swap! prop assoc :foo "me")
(r/flush)
(is (found-in #"hi me" div))
(is (= "hi me." (.-innerText div)))
(is (= 1 @top-ran))
(is (= 4 @ran)))))))
@ -1312,10 +1312,10 @@
[pure-component {:value @prop}])]
(with-mounted-component [component]
(fn [c div]
(is (found-in #"Value foo" div))
(is (= "Value foo" (.-innerText div)))
(swap! prop inc)
(r/flush)
(is (found-in #"Value foo foo" div)))))))
(is (= "Value foo foo" (.-innerText div))))))))
(deftest get-derived-state-from-error-test
(when isClient
@ -1338,10 +1338,10 @@
(wrap-capture-console-error
#(with-mounted-component [component [bad-component]]
(fn [c div]
(is (found-in #"Ok" div))
(is (= "Ok" (.-innerText div)))
(swap! prop inc)
(r/flush)
(is (found-in #"Error" div)))))))))
(is (= "Error" (.-innerText div))))))))))
(deftest get-snapshot-before-update-test
(when isClient
@ -1365,7 +1365,7 @@
(fn [c div]
;; Attach to DOM to get real height value
(.appendChild js/document.body div)
(is (found-in #"foo" div))
(is (= "foo" (.-innerText div)))
(swap! prop inc)
(r/flush)
(is (= {:height 20} @did-update))

View File

@ -1,7 +1,7 @@
(ns reagenttest.testwrap
(:require [clojure.test :as t :refer-macros [is deftest]]
[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
(let [state (r/atom {:foo 1})
@ -112,19 +112,19 @@
(fn [c div done]
(u/run-fns-after-render
(fn []
(is (found-in #"value:1:" div))
(is (= "value:1:" (.-innerText div)))
(is (= @ran 1))
(reset! @grand-state {:foobar 2}))
(fn []
(is (= @state {:foo {:bar {:foobar 2}}}))
(is (= @ran 2))
(is (found-in #"value:2:" div))
(is (= "value:2:" (.-innerText div)))
(swap! state update-in [:foo :bar] assoc :foobar 3))
(fn []
(is (= @ran 3))
(is (found-in #"value:3:" div))
(is (= "value:3:" (.-innerText div)))
(reset! state {:foo {:bar {:foobar 3}}
:foo1 {}}))
(fn []
@ -136,23 +136,23 @@
(reset! state {:foo {:bar {:foobar 2}}
:foo2 {}}))
(fn []
(is (found-in #"value:2:" div))
(is (= "value:2:" (.-innerText div)))
(is (= @ran 4))
(reset! @grand-state {:foobar 2}))
(fn []
(is (found-in #"value:2:" div))
(is (= "value:2:" (.-innerText div)))
(is (= @ran 5))
(reset! state {:foo {:bar {:foobar 4}}})
(reset! @grand-state {:foobar 4}))
(fn []
(is (found-in #"value:4:" div))
(is (= "value:4:" (.-innerText div)))
(is (= @ran 6))
(reset! @grand-state {:foobar 4}))
(fn []
(is (found-in #"value:4:" div))
(is (= "value:4:" (.-innerText div)))
(is (= @ran 7)))
done)))))))

View File

@ -27,11 +27,3 @@
(f)
(cb)))))
(reverse fs))))
(defn found-in [re div]
(let [res (.-innerHTML div)]
(if (re-find re res)
true
(do (println "Not found: " res)
false))))