Typed ActorTestKit and ActorContext spawn function

I have complex component implementation which internally needs to create actor/s

for example:

class SubComponent(actorContext: ActorContext[_]) {
    private val a = actorContext.spawn( ... )
}

class MainComponent(actorContext: ActorContext[_]) {
  val subComponent: SubComponent = new SubComponent(actorContext)
}

with akka typed, actors are created with spawn function from ActorContext

I like to test that component with ActorTestKit
is it possible to get ActorContext from ActorTestKit?

ActorTestKit providing also spawn function, but ActorContext and ActorTestKit do not sharing some interface for this functionality.

So it is look like, that without custom interface I can not use provided akka components to solve this problem.

Or do I miss something?

Thank you for answer.

I would have questions about the wisdom of saving an ActorContext in another object, but you should be able to do something like

val testKit = ActorTestKit()

def extractor(contextTo: ActorRef[ActorContext[_]]): Behavior[Nothing] =
  Behaviors.setup { context =>
    contextTo ! context
    Behaviors.empty
  }

val probe = testKit.createTestProbe[ActorContext[_]]()
testKit.spawn(extractor(probe), "dummy-extractor")

val context = probe.receiveMessage(1.minute)

Thank you for proposal,

I am not “saving” it, just propagating it like implicit to be able to create underlying actors

class SubComponent()(implicit actorContext: ActorContext[_]) {
    private val a = actorContext.spawn( ... )
}

class MainComponent()(implicit actorContext: ActorContext[_]) {
  val subComponent: SubComponent = new SubComponent(actorContext)
}

with akka classic, actor was created by actor system, so more like everywhere, was propagated actor system, but akka typed changed that …