-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} | ||
``` |