* Sets up a TestBed with the stubbed CopilotKit service and a configurable * fetch mock, and returns helpers for driving the runtime and flushing async * work. Follows the SIFERS pattern.
()
| 124 | * work. Follows the SIFERS pattern. |
| 125 | */ |
| 126 | function setup() { |
| 127 | TestBed.resetTestingModule(); |
| 128 | stub = new CopilotKitStub(); |
| 129 | const originalFetch = globalThis.fetch; |
| 130 | const fetchMock = vi.fn<typeof fetch>(); |
| 131 | globalThis.fetch = fetchMock as unknown as typeof fetch; |
| 132 | |
| 133 | TestBed.configureTestingModule({ |
| 134 | providers: [{ provide: CopilotKit, useValue: stub }], |
| 135 | }); |
| 136 | |
| 137 | const connect = ( |
| 138 | options: { |
| 139 | list?: boolean; |
| 140 | mutations?: boolean; |
| 141 | wsUrl?: string; |
| 142 | } = {}, |
| 143 | ): void => { |
| 144 | stub.setThreadEndpoints({ |
| 145 | list: options.list ?? true, |
| 146 | inspect: true, |
| 147 | mutations: options.mutations ?? true, |
| 148 | realtimeMetadata: false, |
| 149 | }); |
| 150 | if (options.wsUrl) { |
| 151 | stub.setIntelligence({ wsUrl: options.wsUrl }); |
| 152 | } |
| 153 | stub.setRuntimeUrl("https://runtime.local"); |
| 154 | stub.setRuntimeConnectionStatus( |
| 155 | CopilotKitCoreRuntimeConnectionStatus.Connected, |
| 156 | ); |
| 157 | }; |
| 158 | |
| 159 | // Drains the microtask/macrotask queue so the rxjs fetch pipeline (defer → |
| 160 | // fromFetch → json() → reducer) and the signal bridges settle. |
| 161 | const flush = async (): Promise<void> => { |
| 162 | for (let i = 0; i < 5; i += 1) { |
| 163 | await new Promise((resolve) => setTimeout(resolve, 0)); |
| 164 | } |
| 165 | }; |
| 166 | |
| 167 | const teardown = (): void => { |
| 168 | globalThis.fetch = originalFetch; |
| 169 | }; |
| 170 | |
| 171 | return { stub, fetchMock, connect, flush, teardown }; |
| 172 | } |
| 173 | |
| 174 | describe("injectThreads", () => { |
| 175 | let active: ReturnType<typeof setup> | undefined; |
no outgoing calls
no test coverage detected
searching dependent graphs…