Skip to content

Commit

Permalink
Cover custom error
Browse files Browse the repository at this point in the history
Signed-off-by: mramotar <[email protected]>
  • Loading branch information
matt-ramotar committed Jan 7, 2024
1 parent db21cfc commit 9b23435
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,32 @@ class FetcherResponseTests {
)
}

@Test
fun givenAFetcherThatEmitsCustomErrorWhenStreamingThenCustomErrorShouldBeEmitted() = testScope.runTest {
data class TestCustomError(val errorMessage: String)
val customError = TestCustomError("Test custom error")

val store = StoreBuilder.from(
fetcher = Fetcher.ofResultFlow { _: Int ->
flowOf(
FetcherResult.Error.Custom(customError)
)
}
).buildWithTestScope()

assertEmitsExactly(
store.stream(StoreReadRequest.fresh(1)),
listOf(
StoreReadResponse.Loading(origin = StoreReadResponseOrigin.Fetcher()),
StoreReadResponse.Error.Custom(
error = customError,
origin = StoreReadResponseOrigin.Fetcher()
)
)
)
}


private fun <Key : Any, Output : Any> StoreBuilder<Key, Output>.buildWithTestScope() =
scope(testScope).build()
}

0 comments on commit 9b23435

Please sign in to comment.