Skip to content

Commit

Permalink
add KoinScopeComponent test
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudgiuliani committed Jun 5, 2023
1 parent d6c8f87 commit 202a979
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions core/koin-core/src/commonTest/kotlin/org/koin/core/ScopeTest.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,54 @@
package org.koin.core

import org.koin.Simple
import org.koin.core.component.KoinScopeComponent
import org.koin.core.component.getOrCreateScope
import org.koin.core.component.inject
import org.koin.core.context.startKoin
import org.koin.core.error.ClosedScopeException
import org.koin.core.logger.Level
import org.koin.core.module.dsl.scopedOf
import org.koin.core.module.dsl.singleOf
import org.koin.core.parameter.parametersOf
import org.koin.core.qualifier.named
import org.koin.core.scope.Scope
import org.koin.dsl.koinApplication
import org.koin.dsl.module
import kotlin.test.*

class ScopeTest {

private class A
private class B
@Test
fun scope_component() {
abstract class SuperClass : KoinScopeComponent {
override val scope: Scope by getOrCreateScope()
}

class SubClass : SuperClass() {
val a: A by inject()
val b: B by inject()
}

startKoin {
printLogger(Level.DEBUG)
modules(
module {
singleOf(::A)
scope<SubClass> {
scopedOf(::B)
}
}
)
}

with(SubClass()) {
assertTrue { a is A }
assertTrue { b is B }
}
}

@Test
fun `get definition from current scopes type`() {
val koin = koinApplication {
Expand Down

0 comments on commit 202a979

Please sign in to comment.