/kotlin-react-test

Kotlin wrapper for React Test Renderer, which can be used to unit test React components in a Kotlin/JS project.

Primary LanguageKotlinMIT LicenseMIT

Build Maven metadata URL

Kotlin API for React Test Renderer

Kotlin wrapper for React Test Renderer, which can be used to unit test React components in a Kotlin/JS project.

How to Use

Installation

With Gradle (using Kotlin DSL):

repositories {
    maven("https://maven.turtton.net")
}

dependencies {
    implementation("io.github.mysticfall:kotlin-react-test:$version")
}

Alternatively, using Groovy DSL:

repositories {
    maven "https://maven.turtton.net"
}

dependencies {
    implementation "io.github.mysticfall:kotlin-react-test:$version"
}

Code Example

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 {
                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.

LICENSE

This project is provided under the terms of MIT License.