clojure-spec

About: http://clojure.org/about/spec Guide: http://clojure.org/guides/spec API: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html
Aron 2020-07-27T11:11:51.046300Z

where should I look for docs/guide for how to test sideeffects on the frontend with specs?

vemv 2020-07-27T15:03:34.046400Z

do you want to test that side-effects happen? or to avoid them, so that things are more cleanly testable?

Aron 2020-07-27T15:05:30.046600Z

test them

Aron 2020-07-27T15:05:46.046800Z

sadly, no one pays me for code that is pure 🙂

vemv 2020-07-27T15:08:08.047Z

what do you use for frontend? with re-frame you should have effect segregation for free

Aron 2020-07-27T15:08:29.047200Z

the state is handled by react hooks locally in react components so it's not easy to test state transitions. There are specific situations that I want to avoid, so I was thinking I could run the app with generated data and test that specific situations don't occur. Like there is always a button to click or always a feedback message is shown

Aron 2020-07-27T15:09:22.047400Z

the time I started this project re-frame didn't support hooks, which were required by my boss and colleagues

Aron 2020-07-27T15:09:30.047600Z

so I use helix

vemv 2020-07-27T15:19:11.047800Z

not sure if I'd run Spec's generative testing (specifically, spec.test.alpha/check) with side-effectful functions. IME it's the kind of thing that is painful/slow to implement, and later to debug It might be cleaner to generate data with Spec, and pass said data to a vanilla integration test (whether a purely frontend-bound one, or a full-stack one aided by Webdriver)

vemv 2020-07-27T15:21:12.048Z

For completeness, with re-frame I think it's feasible to craft a useful generative test that asserts that interactions always yield a valid application state e.g. click X + click Y, in any order, generate events a, b, c all of which are valid and form a valid new app state All this side-effect free (thanks to the indirection bought by events)

Aron 2020-07-27T15:46:13.048200Z

The first suggestion with the integration test makes sense, it's what direction I was going, but I wasn't sure if there is no other way.

Aron 2020-07-27T15:46:29.048400Z

The second part with re-frame I don't understand, or maybe I understand just don't see how it is relevant?

robertfw 2020-07-27T20:05:59.048600Z

I do stateful generative testing but not on the frontend, so I can't help with specifics there. But I can confirm what @vemv says - it is a bit painful and slow to implement. I've gone through a few iterations and am finally at a spot where I think we are taming the beast, but it's taken some work getting there and we have some work to go to get it running in a more reasonable amount of time.

vemv 2020-07-27T20:10:44.048800Z

> The second part with re-frame I don't understand, or maybe I understand just don't see how it is relevant? it's relevant because it attempts to show how one could write a generative, integration-ish side-effect-free test using a specific framework. Don't know helix myself so yeah it may have limited utility :)

Aron 2020-07-27T20:25:20.049Z

I still don't understand, are you saying I should use a different library? Or framework, although I do not use frameworks so I hesitate to use the word framework.

vemv 2020-07-27T21:01:57.049200Z

no, I'm stating a technique that may be translated to other (but not all) libraries/frameworks

Aron 2020-07-27T21:02:37.049400Z

Wouldn't that mean that I would have to start over and write the whole thing in a different style?

Aron 2020-07-27T21:02:51.049600Z

so are you saying this for consideration for future projects?

vemv 2020-07-27T21:08:46.049800Z

IDK, I don't know helix so I don't know how practical the described techique could be for you. In the end it's just food for thought :)