-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathwithSplitFactory.test.tsx
More file actions
83 lines (73 loc) · 3.33 KB
/
withSplitFactory.test.tsx
File metadata and controls
83 lines (73 loc) · 3.33 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
77
78
79
80
81
82
83
import * as React from 'react';
import { render } from '@testing-library/react';
/** Mocks */
import { mockSdk, Event } from './testUtils/mockSplitFactory';
jest.mock('@splitsoftware/splitio/client', () => {
return { SplitFactory: mockSdk() };
});
import { SplitFactory } from '@splitsoftware/splitio/client';
import { sdkBrowser } from './testUtils/sdkConfigs';
import { SplitClient } from '../SplitClient';
jest.mock('../SplitClient');
/** Test target */
import { ISplitFactoryChildProps } from '../types';
import { withSplitFactory } from '../withSplitFactory';
describe('withSplitFactory', () => {
test('passes no-ready props to the child if initialized with a no ready factory (e.g., using config object).', () => {
const Component = withSplitFactory(sdkBrowser)(
({ factory, isReady, isReadyFromCache, hasTimedout, isTimedout, isDestroyed, lastUpdate }: ISplitFactoryChildProps) => {
expect(factory).toBeInstanceOf(Object);
expect([isReady, isReadyFromCache, hasTimedout, isTimedout, isDestroyed, lastUpdate]).toStrictEqual([false, false, false, false, false, 0]);
return null;
}
);
render(<Component />);
});
test('passes ready props to the child if initialized with a ready factory.', (done) => {
const outerFactory = SplitFactory(sdkBrowser);
(outerFactory as any).client().__emitter__.emit(Event.SDK_READY);
(outerFactory.manager().names as jest.Mock).mockReturnValue(['split1']);
outerFactory.client().ready().then(() => {
const Component = withSplitFactory(undefined, outerFactory)(
({ factory, isReady, isReadyFromCache, hasTimedout, isTimedout, isDestroyed, lastUpdate }: ISplitFactoryChildProps) => {
expect(factory).toBe(outerFactory);
expect([isReady, isReadyFromCache, hasTimedout, isTimedout, isDestroyed, lastUpdate]).toStrictEqual([true, false, false, false, false, 0]);
return null;
}
);
render(<Component />);
done();
});
});
test('passes Split props and outer props to the child.', () => {
const Component = withSplitFactory(sdkBrowser)<{ outerProp1: string, outerProp2: number }>(
({ outerProp1, outerProp2, factory, isReady, isReadyFromCache, hasTimedout, isTimedout, isDestroyed, lastUpdate }) => {
expect(outerProp1).toBe('outerProp1');
expect(outerProp2).toBe(2);
expect(factory).toBeInstanceOf(Object);
expect([isReady, isReadyFromCache, hasTimedout, isTimedout, isDestroyed, lastUpdate]).toStrictEqual([false, false, false, false, false, 0]);
return null;
}
);
render(<Component outerProp1='outerProp1' outerProp2={2} />);
});
test('passes Status props to SplitFactory.', () => {
const updateOnSdkUpdate = true;
const updateOnSdkTimedout = false;
const updateOnSdkReady = true;
const updateOnSdkReadyFromCache = false;
const Component = withSplitFactory(sdkBrowser)<{ outerProp1: string, outerProp2: number }>(
() => null, updateOnSdkUpdate, updateOnSdkTimedout, updateOnSdkReady, updateOnSdkReadyFromCache
);
render(<Component outerProp1='outerProp1' outerProp2={2} />);
expect(SplitClient).toHaveBeenLastCalledWith(
expect.objectContaining({
updateOnSdkUpdate,
updateOnSdkTimedout,
updateOnSdkReady,
updateOnSdkReadyFromCache
}),
expect.anything(),
);
});
});