Fork me on GitHub
#re-frame
<
2015-07-11
>
estsauver04:07:59

@mikethompson: I ended up writing a helper that looks something like this:

estsauver04:07:02

(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))

estsauver04:07:41

Seems like Specter would have worked for that too.

estsauver05:07:47

I also put together a patch to cleanup the compose middleware function:

estsauver06:07:03

For testing, do you all just reach into app-state to setup the preconditions for whatever you need?

mikethompson10:07:23

@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.

mikethompson10:07:01

But there are ways ...

mikethompson10:07:09

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.

mikethompson10:07:00

----- 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.

estsauver11:07:34

Yah, that’s reasonable.

estsauver11:07:58

Cool, thank you