Skip to content

Add errors-test module with test utilities #14

@Alex009

Description

@Alex009

When i try to test ViewModel that use ExceptionHandler i need to create test version of ExceptionHandler.
here draft:

import dev.icerock.moko.errors.handler.ExceptionHandler
import dev.icerock.moko.errors.handler.ExceptionMapper

expect class TestsExceptionHandler<T : Any>(
    exceptionMapper: ExceptionMapper<T>
) : ExceptionHandler {
    val catchedExceptions: List<Throwable>
}

android:

import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.LifecycleOwner
import dev.icerock.moko.errors.handler.ExceptionHandler
import dev.icerock.moko.errors.handler.ExceptionHandlerContext
import dev.icerock.moko.errors.handler.ExceptionMapper
import dev.icerock.moko.mvvm.dispatcher.EventsDispatcher

actual class TestsExceptionHandler<T : Any> actual constructor(
    private val exceptionMapper: ExceptionMapper<T>
) : ExceptionHandler {

    private val _catchedExceptions = mutableListOf<Throwable>()
    actual val catchedExceptions: List<Throwable> = _catchedExceptions

    override fun bind(lifecycleOwner: LifecycleOwner, activity: FragmentActivity) {
        TODO("Not yet implemented")
    }

    override fun <R> handle(block: suspend () -> R): ExceptionHandlerContext<R> {
        return ExceptionHandlerContext.invoke(
            exceptionMapper = exceptionMapper,
            eventsDispatcher = EventsDispatcher(),
            onCatch = _catchedExceptions::add,
            block = block
        )
    }
}

ios:

import dev.icerock.moko.errors.handler.ExceptionHandler
import dev.icerock.moko.errors.handler.ExceptionHandlerContext
import dev.icerock.moko.errors.handler.ExceptionMapper
import dev.icerock.moko.mvvm.dispatcher.EventsDispatcher
import platform.UIKit.UIViewController

actual class TestsExceptionHandler<T : Any> actual constructor(
    private val exceptionMapper: ExceptionMapper<T>
) : ExceptionHandler {
    private val _catchedExceptions = mutableListOf<Throwable>()
    actual val catchedExceptions: List<Throwable> = _catchedExceptions

    override fun <R> handle(block: suspend () -> R): ExceptionHandlerContext<R> {
        return ExceptionHandlerContext.invoke(
            exceptionMapper = exceptionMapper,
            eventsDispatcher = EventsDispatcher(),
            onCatch = _catchedExceptions::add,
            block = block
        )
    }

    override fun bind(viewController: UIViewController) {
        TODO("Not yet implemented")
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions