Skip to content

Commit 0c5ead6

Browse files
committed
fix tests
1 parent e030327 commit 0c5ead6

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

packages/experiment-tag/src/experiment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ export class DefaultWebExperimentClient implements WebExperimentClient {
281281

282282
// fire stored redirect impressions upon startup
283283
this.fireStoredRedirectImpressions().catch();
284-
this.addPageChangeSubscriber(() => {
285-
// support custom redirect handler
284+
// Subscribe directly to url_change events to fire redirect impressions
285+
this.messageBus.subscribe('url_change', () => {
286286
this.fireStoredRedirectImpressions().catch();
287287
});
288288

packages/experiment-tag/test/experiment.test.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -293,27 +293,24 @@ describe('initializeExperiment', () => {
293293
// Clear exposure tracking before simulating URL change
294294
mockExposureInternal.mockClear();
295295

296-
// Ensure messageBus exists before publishing
297-
if ((client as any).messageBus) {
298-
// Simulate URL change event after redirect
299-
(client as any).messageBus.publish('url_change', {});
296+
// Simulate URL change event after redirect
297+
(client as any).messageBus.publish('url_change', {});
300298

301-
// Wait for async operations to complete
302-
await new Promise((resolve) => setTimeout(resolve, 10));
299+
// Wait for async operations to complete
300+
await new Promise((resolve) => setTimeout(resolve, 10));
303301

304-
// Verify exposureInternal was called with the correct flag key
305-
expect(mockExposureInternal).toHaveBeenCalledTimes(1);
306-
expect(mockExposureInternal.mock.calls[0][0]).toBe('test');
302+
// Verify exposureInternal was called with the correct flag key
303+
expect(mockExposureInternal).toHaveBeenCalledTimes(1);
304+
expect(mockExposureInternal.mock.calls[0][0]).toBe('test');
307305

308-
// Check that the sourceVariant parameter contains the expected properties
309-
const sourceVariant: any = mockExposureInternal.mock.calls[0][1];
310-
expect(sourceVariant).toBeDefined();
311-
expect(sourceVariant.variant).toBeDefined();
312-
expect(sourceVariant.variant.key).toBe('treatment');
306+
// Check that the sourceVariant parameter contains the expected properties
307+
const sourceVariant: any = mockExposureInternal.mock.calls[0][1];
308+
expect(sourceVariant).toBeDefined();
309+
expect(sourceVariant.variant).toBeDefined();
310+
expect(sourceVariant.variant.key).toBe('treatment');
313311

314-
// Verify sessionStorage was cleared after tracking
315-
expect(mockGlobal.sessionStorage.getItem(redirectStorageKey)).toBeNull();
316-
}
312+
// Verify sessionStorage was cleared after tracking
313+
expect(mockGlobal.sessionStorage.getItem(redirectStorageKey)).toBeNull();
317314
});
318315

319316
test('control variant on control page - should not redirect but call exposure', async () => {

0 commit comments

Comments
 (0)