-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathwithSplitTreatments.test.tsx
More file actions
76 lines (59 loc) · 2.61 KB
/
withSplitTreatments.test.tsx
File metadata and controls
76 lines (59 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import * as React from 'react';
import { act, render } from '@testing-library/react';
/** Mocks */
import { mockSdk, getLastInstance, Event } from './testUtils/mockSplitFactory';
jest.mock('@splitsoftware/splitio/client', () => {
return { SplitFactory: mockSdk() };
});
import { SplitFactory } from '@splitsoftware/splitio/client';
import { sdkBrowser } from './testUtils/sdkConfigs';
import { INITIAL_STATUS } from './testUtils/utils';
/** Test target */
import { withSplitFactory } from '../withSplitFactory';
import { withSplitClient } from '../withSplitClient';
import { withSplitTreatments } from '../withSplitTreatments';
import { getTreatments } from '../utils';
const featureFlagNames = ['split1', 'split2'];
describe('withSplitTreatments', () => {
it(`passes Split props and outer props to the child.
In this test, the value of "props.treatments" is obtained by the function "getTreatments",
and not "client.getTreatmentsWithConfig" since the client is not ready.`, () => {
const Component = withSplitFactory(sdkBrowser)<{ outerProp1: string, outerProp2: number }>(
({ outerProp1, outerProp2, factory }) => {
const SubComponent = withSplitClient('user1')<{ outerProp1: string, outerProp2: number }>(
withSplitTreatments(featureFlagNames)(
(props) => {
const clientMock = factory!.client('user1');
expect((clientMock.getTreatmentsWithConfig as jest.Mock).mock.calls.length).toBe(0);
expect(props).toStrictEqual({
...INITIAL_STATUS,
factory: factory, client: clientMock,
outerProp1: 'outerProp1', outerProp2: 2,
treatments: getTreatments(featureFlagNames, true),
});
return null;
}
)
);
return <SubComponent outerProp1={outerProp1} outerProp2={outerProp2} />;
});
render(<Component outerProp1='outerProp1' outerProp2={2} />);
});
it('disabling "updateOnSdkTimedout" requires passing `false` in all HOCs since the default value is `true`.', () => {
let renderCount = 0;
const Component = withSplitFactory(sdkBrowser)(
withSplitClient(sdkBrowser.core.key)(
withSplitTreatments(featureFlagNames)(
(props) => {
renderCount++;
expect(props.hasTimedout).toBe(false);
return null;
}, undefined, false
), undefined, false
), undefined, false
);
render(<Component />);
act(() => getLastInstance(SplitFactory).client().__emitter__.emit(Event.SDK_READY_TIMED_OUT));
expect(renderCount).toBe(1);
});
});