|
1 | 1 | /** |
2 | | - * Copyright 2025, Optimizely |
| 2 | + * Copyright 2025-2026, Optimizely |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
17 | | -import { describe, it, expect } from 'vitest'; |
| 17 | +import { describe, it, expect, vi, beforeEach } from 'vitest'; |
| 18 | + |
| 19 | +vi.mock('./optimizely', () => { |
| 20 | + return { |
| 21 | + default: vi.fn(), |
| 22 | + }; |
| 23 | +}); |
18 | 24 |
|
19 | 25 | import { getOptimizelyInstance } from './client_factory'; |
20 | 26 | import { createStaticProjectConfigManager } from './project_config/config_manager_factory'; |
21 | 27 | import Optimizely from './optimizely'; |
22 | 28 |
|
23 | 29 | describe('getOptimizelyInstance', () => { |
| 30 | + const MockedOptimizely = vi.mocked(Optimizely); |
| 31 | + |
| 32 | + beforeEach(() => { |
| 33 | + MockedOptimizely.mockClear(); |
| 34 | + }); |
| 35 | + |
24 | 36 | it('should throw if the projectConfigManager is not a valid ProjectConfigManager', () => { |
25 | 37 | expect(() => getOptimizelyInstance({ |
26 | 38 | projectConfigManager: undefined as any, |
@@ -58,4 +70,24 @@ describe('getOptimizelyInstance', () => { |
58 | 70 |
|
59 | 71 | expect(optimizelyInstance).toBeInstanceOf(Optimizely); |
60 | 72 | }); |
| 73 | + |
| 74 | + it('should pass the provided UNSTABLE_conditionEvaluators to the Optimizely instance', () => { |
| 75 | + const mockConditionEvaluators = { |
| 76 | + foo: () => true, |
| 77 | + bar: () => false, |
| 78 | + }; |
| 79 | + |
| 80 | + const optimizely = getOptimizelyInstance({ |
| 81 | + projectConfigManager: createStaticProjectConfigManager({ |
| 82 | + datafile: '{}', |
| 83 | + }), |
| 84 | + requestHandler: {} as any, |
| 85 | + // eslint-disable-next-line @typescript-eslint/ban-ts-comment |
| 86 | + // @ts-ignore |
| 87 | + UNSTABLE_conditionEvaluators: mockConditionEvaluators, |
| 88 | + }); |
| 89 | + |
| 90 | + expect(optimizely).toBe(MockedOptimizely.mock.instances[0]); |
| 91 | + expect(MockedOptimizely.mock.calls[0][0].UNSTABLE_conditionEvaluators).toBe(mockConditionEvaluators); |
| 92 | + }); |
61 | 93 | }); |
0 commit comments