Skip to content

Commit

Permalink
Add redukt-test-thunk README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
lupuuss committed Feb 6, 2023
1 parent 618fdec commit be45235
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions redukt-test-thunk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# ReduKt Test Thunk

ReduKt Test Thunk provides tools to test thunks. It's an extension of [ReduKt Test](../redukt-test) and
provides very similar API.

### Quick start

Testing thunks is very similar to testing middlewares
described [here](../redukt-test/README.md#testing-middlewares-basics),
and you should start there. Examples below shows simple example of testing thunks:

* For `Thunk`:

```kotlin
val CustomThunk = Thunk<AppState> {
if (currentState.condition) dispatch(ActionA)
}

class CustomThunkTest {
private val tester = CustomThunk.tester(initialState = AppState())

@Test
fun test() = tester.test {
// given
currentState = AppState(condition = true)
// when
testExecute()
// then
assertSingleActionEquals(ActionA)
}
}
```

* For `CoThunk` (requires `runTest`
from [kotlinx-coroutines-test](https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-test)):

```kotlin
val CustomCoThunk = CoThunk<AppState> {
if (currentState.condition) {
delay(1_000)
dispatch(ActionA)
}
}

class CustomCoThunkTest {
private val tester = CustomCoThunk.tester(initialState = AppState())

@Test
fun test() = runTest {
tester.test {
// given
currentState = AppState(condition = true)
// when
testExecute() // suspends until thunk function completes
// then
assertSingleActionEquals(ActionA)
}
}
}
```

0 comments on commit be45235

Please sign in to comment.