diff --git a/formula/src/test/java/com/instacart/formula/FormulaRuntimeTest.kt b/formula/src/test/java/com/instacart/formula/FormulaRuntimeTest.kt index d8f52823..2920f3ce 100644 --- a/formula/src/test/java/com/instacart/formula/FormulaRuntimeTest.kt +++ b/formula/src/test/java/com/instacart/formula/FormulaRuntimeTest.kt @@ -7,6 +7,7 @@ import com.instacart.formula.internal.ClearPluginsRule import com.instacart.formula.internal.TestInspector import com.instacart.formula.internal.Try import com.instacart.formula.rxjava3.RxAction +import com.instacart.formula.rxjava3.RxJavaRuntime import com.instacart.formula.subjects.ChildActionFiresParentEventOnStart import com.instacart.formula.subjects.ChildMessageNoParentStateChange import com.instacart.formula.subjects.ChildMessageTriggersEventTransitionInParent @@ -1111,6 +1112,24 @@ class FormulaRuntimeTest(val runtime: TestableRuntime, val name: String) { assertThat(error).isInstanceOf(IllegalStateException::class.java) } + @Test fun `adding duplicate child logs an exception`() { + val logs = mutableListOf() + RxJavaRuntime.setDefaultErrorHandler { logs.add(it.localizedMessage) } + + val result = Try { + val formula = DynamicParentFormula() + runtime.test(formula, Unit) + .output { addChild(TestKey("1")) } + .output { addChild(TestKey("1")) } + } + + val error = result.errorOrNull()?.cause + assertThat(error).isNull() + assertThat(logs).hasSize(1) + val log = logs.first() + assertThat(log).isEqualTo("Duplicate child key: TestKey(id=1)") + } + @Test fun `parent removal triggers childs terminate message`() { val terminateFormula = TerminateFormula()