Fork me on GitHub
#reagent
<
2020-07-31
>
Mark Gerard17:07:37

Hey! Could someone help me with this error?

expected: (= "2020" (->> (r/as-element [footer-component]) (rtl/render) (.getByText "copyright") (.-innerHTML)))
  actual: #object[ReferenceError ReferenceError: document is not defined]
I am trying to test drive my component, and here is the component def:
(ns components.footer-test
  (:require
   [reagent.core :as r]
   ["@testing-library/react" :as rtl]
   [components.footer :refer [footer-component]]
   [cljs.test :refer [deftest testing is use-fixtures]]))

(deftest test-that-copyright-has-correct-year
  (testing "Test Correct year in copyright"
    (is
     (=
      "2020"
      (-> (r/as-element [footer-component])
          (rtl/render)
          (.getByText "copyright")
          (.-innerHTML))))))
What might be the issue? Do I need to call some function to init the document?

p-himik17:07:01

Always look at the stacktrace. If it ends up in some JS library, then chances are that the problem is with the usage of that library and not with the CLJS code itself.

Mark Gerard17:07:22

I know it is not a problem with CLJS ....

p-himik17:07:23

Well, either way that issue has a fix.

Mark Gerard17:07:41

changed :target :node-test to :target browser-test. Got it working, thanks a bunch @U2FRKM4TW

👍 3