This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
@mikethompson: I ended up writing a helper that looks something like this:
(defn has-elements?
[generated-hiccup hickory-selector]
;; The hickory conversion function seems to need to be a seq of components?
(->> (hiccup-fragment-to-hickory [generated-hiccup])
(map #(hick/select hickory-selector %))
flatten
not-empty))
For testing, do you all just reach into app-state to setup the preconditions for whatever you need?
@estsauver: With re-frame, there's three parts to test: 1. event handlers 2. subscription handlers 3. views Of these, event handlers are the easiest to test. First, create the event handler like this:
(defn my-handler
[db v]
... return a modified version of db)
Then, register it:
(register-handler :some-id [some-middleware] my-handler)
At this point, the testing process for my-handler
is straightforward because it is a pure function. Given parameters X and Y, ensure it returns the value X'. Standard stuff.
I would strongly recommend having a checked Schema for db as described here:
https://github.com/Day8/re-frame/wiki/Debugging-Event-Handlers#3-checking-db-integrity
All good. However it isn't as easy for subscription-handlers and views. They are not as pure.But there are ways ...
Here's a subscription handler as presented in the todomvc example: https://github.com/Day8/re-frame/blob/master/examples/todomvc/src/todomvc/subs.cljs#L37-L40
(register-sub
:completed-count
(fn [db _]
(reaction (completed-count (:todos @db)))))
If you wanted to test it, you can refactor, like this ...
First, create a pure function which does the work ...
(defn completed-count-handler
[db v] ;; db is a value, not an atom
..... return a value here based on the values db and v])
Now, register, using a reaction wrapper.
(register-sub :completed-count (fn [db-atom v] (reaction (completed-count-handler @db v))) )
It is now possible to test completed-count-handler
. It is a pure function.-----
Finally, I don't yet have a way for easily testing views that depend on subscriptions ... other than first setting up app-db
... which is possible by messy.