What's your approach to unit-testing React compone...
# javascript
p
What's your approach to unit-testing React components in Kotlin/JS? I found this https://github.com/mysticfall/Kotlin-react-test but it's pretty new - I'm wondering if there are any well-established practices. My goal is to take a component that possibly uses other components under the hood, and both be able to test it by verifying that it calls underlying components correctly, and assert on complete DOM.
In https://github.com/JetBrains/create-react-kotlin-app there's this note "Unit testing is currently not supported in this project. We're now working on the Jest Kotlin wrapper. Stay tuned!". It's been there for 4 years already! :(
I've searched for a relevant ticket in YouTrack, but I don't see one, so I created this: [KT-49610] Allow unit-testing React components
p
t
I'm trying to get this working: https://github.com/JetBrains/kotlin-wrappers/tree/master/kotlin-react-dom-test-utils So far I am not able to get a test running, will keep trying.
t
@Tim Lavers Test utils works fine. Example Important: • Async JS test must return
Promise<Unit>
◦ Multiplatform adapter - TestResult
Simulate
works •
dispatchEvent
, which used in React docs - doesn’t work 😞
runReactTest
will be available in next release 🙂
t
Thanks @turansky I am following the code in your Seskar repo. It's working. I was not even close to getting things going so thanks again.
t
runReactTest
released in
pre.480
🙌 1
e
I came around https://youtrack.jetbrains.com/issue/KT-49610/ just now trying to understand the testing situation. Seems like there is still no Jest wrapper for Kotlin, but will it work anyway if run on Mocha? Just asking as Jest is the recommended test framework for React.
t
What is your test cases?
e
Oh I was just wondering how people are approaching unit testing for K/JS React apps. Mostly wondering if there are limitations in the way components can be tested, compared to a pure CRA solution
t
compared to a pure CRA solution
Do you have examples?
e
Not really, not yet at least. I'm evaluating frameworks for VS Code webviews, and the choice is between • Angular (which I have used for many years now) • React (with TS) • React (with K/JS) The point is I don't want to find myself in a situation where I can't properly test the UI