Skip to content

Commit 432d308

Browse files
committed
Extend provider test with flag deletion.
1 parent a82e1c6 commit 432d308

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/provider.test.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,38 @@ describe('LDProvider', () => {
506506
});
507507
});
508508

509+
test('handles deletion of flags', async () => {
510+
mockLDClient.on.mockImplementation((_e: string, cb: (c: LDFlagChangeset) => void) => {
511+
cb({ 'another-test-flag': { current: undefined, previous: true }, 'test-flag': { current: false, previous: true } });
512+
});
513+
const props: ProviderConfig = { clientSideID, reactOptions: { useCamelCaseFlagKeys: false } };
514+
const LaunchDarklyApp = (
515+
<LDProvider {...props}>
516+
<App />
517+
</LDProvider>
518+
);
519+
const instance = create(LaunchDarklyApp).root.findByType(LDProvider).instance as EnhancedComponent;
520+
const mockSetState = jest.spyOn(instance, 'setState');
521+
522+
await instance.componentDidMount();
523+
524+
// Each set of the state depends on the previous state, so to re-create the final state, we need to call the
525+
// setState function for each call.
526+
let finalState = previousState;
527+
528+
for (const call of mockSetState.mock.calls) {
529+
const setStateFunction = call[0] as (p: ProviderState) => ProviderState;
530+
finalState = setStateFunction(finalState);
531+
}
532+
533+
expect(mockLDClient.on).toHaveBeenCalledWith('change', expect.any(Function));
534+
expect(finalState).toMatchObject({
535+
flagKeyMap: {},
536+
unproxiedFlags: { 'test-flag': false },
537+
flags: { 'test-flag': false },
538+
});
539+
});
540+
509541
test(`if props.deferInitialization is true, ld client will only initialize once props.user is defined`, async () => {
510542
options = { ...options, bootstrap: {} };
511543
const props: ProviderConfig = { clientSideID, deferInitialization: true, options };

0 commit comments

Comments
 (0)