Skip to content

Commit 5bb4ddb

Browse files
committed
test: add test for when bootstraped flags when client fails initialization
1 parent 447ec6a commit 5bb4ddb

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/provider.test.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,40 @@ describe('LDProvider', () => {
169169
expect(initialState.flags).toEqual({});
170170
});
171171

172+
test('ld client keeps bootstrapped flags, even when it failed to initialize', async () => {
173+
const context: LDContext = { key: 'yus', kind: 'user', name: 'yus ng' };
174+
const options: LDOptions = {
175+
bootstrap: {
176+
'test-flag': true
177+
}
178+
};
179+
const props: ProviderConfig = { clientSideID, context, options };
180+
181+
mockInitLDClient.mockImplementation(() => ({
182+
error: true,
183+
flags: {},
184+
ldClient: mockLDClient,
185+
}));
186+
187+
const LaunchDarklyApp = (
188+
<LDProvider {...props}>
189+
<App />
190+
</LDProvider>
191+
);
192+
const instance = create(LaunchDarklyApp).root.findByType(LDProvider).instance as EnhancedComponent
193+
instance.setState = jest.fn();
194+
await instance?.componentDidMount()
195+
196+
expect(mockInitLDClient).toHaveBeenCalledWith(clientSideID, context, options, undefined);
197+
expect(instance.setState).toHaveBeenCalledWith({
198+
error: true,
199+
flags: { testFlag: true},
200+
unproxiedFlags: { 'test-flag': true,},
201+
flagKeyMap: { testFlag: 'test-flag'},
202+
ldClient: mockLDClient,
203+
});
204+
});
205+
172206
test('ld client is bootstrapped correctly and transforms keys to camel case', () => {
173207
const context: LDContext = { key: 'yus', kind: 'user', name: 'yus ng' };
174208
const options: LDOptions = {

0 commit comments

Comments
 (0)