provideAgentValue

Provides an agent a test already holds, so the component under test receives that exact object from injectAgent(). Use it to hand a component a mock, such as mockAgent() from @threadplane/angular/chat, or any hand-built agent. Where the test wants the real agent over an in-memory session instead, use provideFakeAgent.

Pass an AgentRef first to answer injectAgent(ref) as well. As with provideAgent(ref, …), the ref-less injectAgent() at that injector level then returns the same agent, and the last provider wins when several are given. Under a ref declared with a backend's session type the agent may be a core-shaped mock: a member only the backend has is then undefined on it, so add the members the component under test calls.

AGENT_LIFECYCLE resolves to the agent's own lifecycle object, so a mock's writable marks drive whatever reads the token. An agent with no lifecycle gets one whose milestones all stay null.

The test owns the agent. The injector does not stop or dispose it, does not list it in AgentLifecycleRegistry, and does not register it for development-install collection.

import { provideAgentValue } from '@threadplane/angular/testing';

Declaration · overload 1

export declare function provideAgentValue<TSession extends AgentSessionLike>(ref: AgentRef<TSession>, agent: Agent<NoInfer<TSession>> | Agent): Provider[];

Type parameters

Parameters

ref · required
AgentRef<TSession>
agent · required
Agent<NoInfer<TSession>> | Agent

Returns

Provider[]

Examples

const agent = mockAgent({ status: 'running' });
TestBed.configureTestingModule({ providers: [provideAgentValue(agent)] });

Declaration · overload 2

export declare function provideAgentValue<TSession extends AgentSessionLike = AgentSession>(agent: Agent<TSession>): Provider[];

Type parameters

Parameters

agent · required
Agent<TSession>

Returns

Provider[]