TestSwrClient

This extended interface of the SwrClient provides the capability to mock specific queries and mutations for the purpose of testing. By registering certain keys as mocks, you can control the behavior of these specific keys while the rest of the keys function normally. This allows for more targeted and precise testing of your application.

val client = SwrCache(..)
val testClient = client.test {
on(MyQueryId) { "returned fake data" }
}

testClient.doSomething()

Inheritors

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
abstract val errorRelay: Flow<ErrorRecord>

Functions

Link copied to clipboard
abstract fun gc(level: MemoryPressureLevel)
Link copied to clipboard
abstract fun <T, S> getInfiniteQuery(key: InfiniteQueryKey<T, S>, marker: Marker): InfiniteQueryRef<T, S>
Link copied to clipboard
abstract fun <T, S> getMutation(key: MutationKey<T, S>, marker: Marker): MutationRef<T, S>
Link copied to clipboard
abstract fun <T> getQuery(key: QueryKey<T>, marker: Marker): QueryRef<T>
Link copied to clipboard
abstract fun <T, S> on(id: InfiniteQueryId<T, S>, fetch: FakeInfiniteQueryFetch<T, S>)

Mocks the query process corresponding to InfiniteQueryId.

abstract fun <T, S> on(id: MutationId<T, S>, mutate: FakeMutationMutate<T, S>)

Mocks the mutation process corresponding to MutationId.

abstract fun <T> on(id: QueryId<T>, fetch: FakeQueryFetch<T>)

Mocks the query process corresponding to QueryId.

Link copied to clipboard
abstract fun onMount(id: String)
Link copied to clipboard
abstract fun onUnmount(id: String)
Link copied to clipboard
abstract fun perform(sideEffects: QueryEffect): Job
Link copied to clipboard
abstract fun <T, S> prefetchInfiniteQuery(key: InfiniteQueryKey<T, S>, marker: Marker): Job
Link copied to clipboard
abstract fun <T> prefetchQuery(key: QueryKey<T>, marker: Marker): Job
Link copied to clipboard
abstract fun purgeAll()
Link copied to clipboard
fun SwrClient.test(initializer: TestSwrClient.() -> Unit = {}): TestSwrClient

Switches SwrClient to a test interface.