This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
(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:
Then, register it:
(defn my-handler [db v] ... return a modified version of db)
At this point, the testing process for
(register-handler :some-id [some-middleware] my-handler)
my-handleris 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.
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
If you wanted to test it, you can refactor, like this ... First, create a pure function which does the work ...
(register-sub :completed-count (fn [db _] (reaction (completed-count (:todos @db)))))
Now, register, using a reaction wrapper.
(defn completed-count-handler [db v] ;; db is a value, not an atom ..... return a value here based on the values db and v])
It is now possible to test
(register-sub :completed-count (fn [db-atom v] (reaction (completed-count-handler @db v))) )
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.