Kotlin wrapper for React Test Renderer, which can be used to unit test React components in a Kotlin/JS project.
With Gradle (using Kotlin DSL):
implementation("io.github.mysticfall:kotlin-react-test:1.2.0")
Alternatively, using Groovy DSL:
implementation "io.github.mysticfall:kotlin-react-test:1.2.0"
The most straightforward way of using the library is to make your test class implement
ReactTestSupport
, as shown below:
import mysticfall.kotlin.react.test.ReactTestSupport
class ComponentTest : ReactTestSupport {
@Test
fun testHeaderTitle() {
val renderer = render {
HeaderTitle {
attrs {
title = "Kotlin/JS"
}
}
}
val title = renderer.root.findByType(HeaderTitle)
assertEquals("Kotlin/JS", title.props.title)
}
}
The project itself has quite an extensive set of test cases, which can serve as examples that show how various features of React Test Renderer can be used in Kotlin.
This project is provided under the terms of MIT License.