diff --git a/project.clj b/project.clj index bb5f8453..cfdd8e26 100644 --- a/project.clj +++ b/project.clj @@ -24,9 +24,9 @@ [doo "0.1.11"] [cljsjs/prop-types "15.7.2-0"] - [cljsjs/react "18.2.0-1"] - [cljsjs/react-dom "18.2.0-1"] - [cljsjs/react-dom-server "18.2.0-1"]] + [cljsjs/react "18.3.1-1"] + [cljsjs/react-dom "18.3.1-1"] + [cljsjs/react-dom-server "18.3.1-1"]] :source-paths ["demo" "test" "examples/todomvc/src" "examples/simple/src" "examples/geometry/src"] :resource-paths ["site" "target/cljsbuild/client" "target/cljsbuild/client-npm"]}} diff --git a/test/reagenttest/utils.clj b/test/reagenttest/utils.clj index c7421059..32ca3500 100644 --- a/test/reagenttest/utils.clj +++ b/test/reagenttest/utils.clj @@ -50,9 +50,11 @@ (done#))) (.catch (fn [e#] (js/clearTimeout timeout#) + (js/console.error "Promise failed in async macro" e#) (cljs.test/is (not e#)) (done#)))) (catch js/Error e# (js/clearTimeout timeout#) + (js/console.error "Error in async macro" e#) (cljs.test/is (not e#)) (done#))))))) diff --git a/test/reagenttest/utils.cljs b/test/reagenttest/utils.cljs index 7d41c734..2def863f 100644 --- a/test/reagenttest/utils.cljs +++ b/test/reagenttest/utils.cljs @@ -2,7 +2,7 @@ (:require-macros [reagenttest.utils :refer [act]]) (:require ["react" :as react] [reagent.core :as r] - [reagent.debug :as debug] + [reagent.debug :as debug :refer [dev?]] [reagent.dom.client :as rdomc] [reagent.dom.server :as server] [reagent.impl.template :as tmpl])) @@ -106,18 +106,31 @@ (defn act* "Run f to trigger Reagent updates, will return Promise which will resolve after - Reagent and React render." + Reagent and React render. + + In production builds, the React.act isn't available, + so just mock with 17ms timeout... Hopefully that usually + is enough time for React to flush the queue?" [f] ;; async act doesn't return a real promise (with chainable then), ;; so wrap it. - (js/Promise. - (fn [resolve reject] - (try - (.then (react/act f) - resolve - reject) - (catch :default e - (reject e)))))) + (if (dev?) + (js/Promise. + (fn [resolve reject] + (try + (.then (react/act f) + resolve + reject) + (catch :default e + (reject e))))) + (js/Promise. + (fn [resolve reject] + (try + (f) + (js/setTimeout (fn [] + (resolve)) + ;; 16.6ms is one animation frame @ 60hz + 17)))))) (defn with-render "Run initial render with React/act and then run