Fork me on GitHub
#cljsrn
<
2017-09-20
>
aaron5106:09:01

With re-frame & react native, how do I render a component so I can assert on it in a doo test? In tests I’m unable to require my-project.core because it requires cljs-exponent, which requires react-native, which fails because “DEV__ is not defined”. Google says this is a babel problem, not sure how to get past this. Once I pass that hurdle, not sure how to “shallow” render the component. CRNA apps use “react-test-renderer”. Reagent has a “render” method but it renders into a DOM element. Any suggestions? Thanks to @tiensonqin & @seantempesta for lein expo(nent) templates!

vikeri08:09:07

I’ve been using enzyme but only to do shallow renders, I think a better solution is to use: https://facebook.github.io/jest/docs/en/tutorial-react-native.html#snapshot-test

vikeri08:09:00

You’d probably want to convert your reagent components to react components using reactify-component

vikeri08:09:58

On a meta level I have found that component tests are less relevant when we have spec + re-frame. It’s more important for us to unit test fns that handle business logic.

vikeri08:09:16

With “us” I mean my colleagues and I.

aaron5106:09:41

Thank you for the tips! Any thoughts on how to require react-native/jest/setup in a cljs.test, to get Jest’s RN mocks? Currently getting “Unexpected token )” type errors because babel isn’t converting. I tried npm i [email protected] and setting .babelrc to {"presets": ["react-native"]} to no effect. Maybe it’s because we’re using doo?

vikeri07:09:00

Yeah I used babel-register to compile required files on the fly. Not very fast but ok for tests

rovanion14:09:52

So, do you guys do (js/JSON.stringify (clj->js {:some "map"})) before sending a payload with js/fetch or do you do something different?

rovanion14:09:12

And another question: Do you guys use react natives fetch or do you pull in some external library for it?

vikeri14:09:37

We use transit-cljs

vikeri14:09:57

We have written our own wrapper for HTTP

rovanion14:09:49

Huh, I thought transit was its own data format and doesn't use JSON over the wire.

vikeri14:09:31

It converts the data to json, but it’s not pretty

rovanion14:09:16

Right, so you need transit on the other side to receive and un-uglify the JSON?

jeaye20:09:51

We use js/fetch and EDN.