Fork me on GitHub
#fulcro
<
2022-12-12
>
tony.kay17:12:57

React 18 notes added to developer’s guide: https://book.fulcrologic.com/#ReactCompatibility

🙏 2
👍 1
tony.kay19:12:18

Actually, it looks like hot code reload is broken with React 18

Andrey Boriskin11:12:37

Do you plan to add support for the new version of react so that everything works without surprises in it? (if possible)))

tony.kay15:12:50

Yes of course. I just have not had time, and probably won't until after the holidays

🥳 2
tony.kay17:12:24

I’ve not had time to test it out much, or add wrappers for the new hooks, but doing that switch in a demo app seemed to work.

sheluchin19:12:58

Is there a way to combine these with fulcro-spec?

(assertions
     (sut/select env "x") =throws=> #"Invalid SQL statement"
     (sut/select env "x") =throws=> (_/ex-data* (_/embeds?* {:stmt "x"
                                                             :type ::ex/incorrect}))))))

tony.kay19:12:13

no idea…that was a contribution that I didn’t write. I don’t use the embeds stuff personally. I’m mainly interested in the fact that it threw. If I want to make assertions about what is in the ex-data, then I’ll try/catch it before making assertions so that I can just treat it as data. Much easier to read and reason about IMO.

tony.kay19:12:31

(-> exdata :stmt) => "x"

tony.kay19:12:50

that way I can also say what each thing is for, so when I get a failure I can read the darn thing

tony.kay19:12:36

(let [e (try ... (catch e e))
      data (ex-data e)]
  (assertions
    "Throws"
    (boolean data) => true
    "Includes the statement"
    (:stmt data e) => "SELECT foo..."
    ...))

tony.kay19:12:24

of course you can mix that with embeds if you really want it 😄

sheluchin20:12:30

Valid points. I was just looking for the idiomatic fulcro-spec approach, but if there aren't well-established patterns to use, I'm okay with using a let as above. ty!

tony.kay20:12:20

Idiomatic is a bit wiggly. The design of the lib is centered around my own test philosophies: • Able to control things not being tested (limit cascading failures and false positives) • Test failures should inform you what went wrong in a way that does NOT involve grokking the test. ◦ Aim for one assertion per behavior with a legible meaning (this is why assertions allows a label for each one) ◦ Wrap the whole thing with reasonable amounts of context (thus the descriptive string support of “component” “behavior” “assertions”, and “provided”)

tony.kay20:12:05

(defn ensure-response! []
  (if (under-attack?)
    (launch-missles!)
    (notify-all-clear!))

...

(specification "ensure-response!"
  (let [launched? (atom false)
    (when-mocking
      ;; Prevent unwanted testing side-effect
      (launch-missles!) => (reset! launched? true)

      (provided "We are under attack!" ; indicate the context to the reader of the test results
        (under-attack?) => true  ; control an external check

        (ensure-response!) ; function under test

        (assertions 
          "we launch our missles"
          @launched? => true))))

tony.kay20:12:06

Output:

ensure-response!
  PROVIDED We are under attack!
    we launch our missles

tony.kay20:12:10

when you get into crazy assertions with nested data then the embed stuff can be nice (that’s why I accepted it), but since I prefer a descrpitive string on everything I want to happen, it isn’t very useful to me

sheluchin20:12:10

Ah, I've not leaned on provided before. I saw it while browsing around the code, but it's not in the book, only the fulcro-spec readme. I'll try to get some use out of that to manage context as you describe. I'm planning on making more sense of my errors+logging and writing tests for more of it, so your advice is timely. In Python I have a very TDD approach, but I kinda get lazy with being able to check everything in Clojure's REPL.

tony.kay20:12:22

In other words I accept that other ppl have preferences that are not mine 😄

tony.kay20:12:59

and I hear you on the lazy, but you’d probably want a regression test to ensure that no one accidentally reorders those then/else clauses in that if in my example 😄

tony.kay20:12:36

but you’d also probably want to make sure launch-missles was somehow impossible from you CI server as well 😛

😄 1
sheluchin20:12:12

And I guess you probably do a lot of your sanity checks by using Guardrails specs. I did a lot of that in one project, but I don't think it's the right tool for data pipelines that process a lot of stuff, because of the performance penalty.

tony.kay19:12:53

See #C015AL9QYH1. I just dropped new versions of 4 libraries to better support unions in forms.