-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Client side exceptions now disposes all subscriptions managed by Kelm
- Loading branch information
1 parent
5529e82
commit be97d24
Showing
3 changed files
with
77 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
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
64 changes: 64 additions & 0 deletions
64
kelm-core/src/test/kotlin/clientSideError/ClientSideErrorTest.kt
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,64 @@ | ||
package clientSideError | ||
|
||
import clientSideError.AElement.Cmd | ||
import clientSideError.AElement.Model | ||
import clientSideError.AElement.Msg | ||
import clientSideError.AElement.Sub | ||
import io.kotlintest.matchers.types.shouldBeInstanceOf | ||
import io.kotlintest.shouldBe | ||
import io.reactivex.Observable | ||
import kelm.ExternalException | ||
import kelm.Kelm | ||
import kelm.SubContext | ||
import kelm.UnhandledException | ||
import kelm.UpdateContext | ||
import org.spekframework.spek2.Spek | ||
|
||
object AElement : Kelm.Element<Model, Msg, Cmd, Sub>() { | ||
var errorToMsgSaved: ExternalException? = null | ||
|
||
object Model | ||
object Msg | ||
object Cmd : kelm.Cmd() | ||
object Sub : kelm.Sub("sub") | ||
|
||
override fun UpdateContext<Model, Msg, Cmd, Sub>.update(model: Model, msg: Msg): Model? { | ||
+Cmd | ||
return null | ||
} | ||
|
||
override fun SubContext<Sub>.subscriptions(model: Model) { | ||
+Sub | ||
} | ||
|
||
override fun errorToMsg(error: ExternalException): Msg? { | ||
errorToMsgSaved = error | ||
return null | ||
} | ||
} | ||
|
||
object ClientSideErrorTest : Spek({ | ||
group("given an element with faulty client side functions") { | ||
val cmdToMaybe = { cmd: Cmd -> error("ops") } | ||
var disposedSub = false | ||
val subToObs = { _: Sub, _: Observable<Msg>, _: Observable<Model> -> | ||
Observable.never<Msg>() | ||
.doOnDispose { disposedSub = true } | ||
} | ||
|
||
test("make sure in case of faulty client-side error, Kelm disposes all subs") { | ||
val ts = AElement | ||
.start( | ||
initModel = Model, | ||
msgInput = Observable.just(Msg), | ||
cmdToMaybe = cmdToMaybe, | ||
subToObs = subToObs | ||
) | ||
.test() | ||
|
||
ts.assertError { it is IllegalStateException && it.localizedMessage == "ops" } | ||
disposedSub shouldBe true | ||
AElement.errorToMsgSaved.shouldBeInstanceOf<UnhandledException>() | ||
} | ||
} | ||
}) |