Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add errors-test module with test utilities #14

Open
Alex009 opened this issue Jan 9, 2021 · 0 comments
Open

Add errors-test module with test utilities #14

Alex009 opened this issue Jan 9, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@Alex009
Copy link
Member

Alex009 commented Jan 9, 2021

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")
    }
}
@Alex009 Alex009 added the enhancement New feature or request label Jan 9, 2021
@Alex009 Alex009 added this to the 0.4.0 milestone Jun 18, 2021
@Alex009 Alex009 modified the milestones: 0.4.0, 0.5.0 Jun 25, 2021
@anton6tak anton6tak modified the milestones: 0.5.0, 0.6.0 Oct 5, 2021
@Alex009 Alex009 modified the milestones: 0.6.0, 0.7.0 Mar 4, 2022
@Alex009 Alex009 removed this from the 0.7.0 milestone Apr 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants