Context
- I have a function that operates on a data structure.
- I have written a spec for the data structure this function operates on.
- This function returns a reagent component that is rendered in a browser (PhantomJS)
- The spec has some optional keys, and depending on whether or not those keys exist in the data when it's passed to the function, the output (component to be rendered in browser) of the aforementioned function will be affected.
- I am looking to use
clojure.test
to compare values of the data structure passed to the function generating the component with values grabbed from the rendered element, so simple unit test or input->output comparison is not what I'm going for here.
Problem
Since calling generate
or sample
on the spec generator will sometimes include or omit the optional fields, I would like to iterate over a reasonably large set of data generated using sample
and test each of the data structures, but I don't know the "right" or idiomatic way to do this.
I have used are
in clojure.test
before, which is great, but since I'm testing against the rendered component in the browser, and are
tests input->output it doesn't seem like the right tool for the job.
Advice on a generally accepted practice here or language/clojure.test feature that would have me doing this in the most idiomatic way would be greatly appreciated.
If possible, I'd use
s/fdef
with:args
,:ret
, and:fn
args to specify the relationship between your function's input and output, and thencheck
the function. There's an example in the testing section of spec guide.This is essentially what
check
does.As for clojure.test integration, you can
check
functions as part of a test suite like this: