Skip to content

Commit 3bed439

Browse files
committed
docs(module-analytics): fix broken abort and ModulesConfigurator examples in testing.md
The abort example never called controller.abort() (so copying it hangs indefinitely) and redeclared `event` from the preceding example in the same code block. The bespoke ModulesConfigurator example destructured `analytics` from initialize() without a type — enableAnalytics only registers the module at runtime, so this doesn't typecheck as written; cast to IAnalyticsProvider, matching what the integration test does.
1 parent e0cf2ef commit 3bed439

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

packages/modules/analytics/docs/testing.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ Resolves with the first matching event — immediately if one was already record
4141
// Rejects after 1000ms if the event never fires
4242
const event = await recorder.waitForAnalytic('button-click', { timeout: 1000 });
4343

44-
// Rejects immediately when the signal aborts
44+
// Rejects as soon as the signal aborts
4545
const controller = new AbortController();
46-
const event = await recorder.waitForAnalytic('button-click', { signal: controller.signal });
46+
const pending = recorder.waitForAnalytic('button-click', { signal: controller.signal });
47+
controller.abort();
48+
49+
await expect(pending).rejects.toThrow();
4750
```
4851

4952
## Using a bespoke `ModulesConfigurator`
@@ -54,6 +57,7 @@ const event = await recorder.waitForAnalytic('button-click', { signal: controlle
5457
import { ModulesConfigurator } from '@equinor/fusion-framework-module';
5558
import { enableAnalytics } from '@equinor/fusion-framework-module-analytics';
5659
import { MockAnalyticsAdapter } from '@equinor/fusion-framework-module-analytics/mock';
60+
import type { IAnalyticsProvider } from '@equinor/fusion-framework-module-analytics';
5761

5862
const recorder = new MockAnalyticsAdapter();
5963
const configurator = new ModulesConfigurator([]);
@@ -62,7 +66,10 @@ enableAnalytics(configurator, (builder) => {
6266
builder.setAdapter('mock', async () => recorder);
6367
});
6468

65-
const { analytics } = await configurator.initialize();
69+
// enableAnalytics only registers the module at runtime, so `initialize()` isn't
70+
// statically typed with an `analytics` property — cast to the real provider type.
71+
const instances = await configurator.initialize();
72+
const { analytics } = instances as unknown as { analytics: IAnalyticsProvider };
6673
analytics.trackAnalytic({ name: 'button-click', value: 'save' });
6774

6875
expect(recorder.getAnalytics('button-click')).toHaveLength(1);

0 commit comments

Comments
 (0)