diff --git a/src/asyncWithLDProvider.test.tsx b/src/asyncWithLDProvider.test.tsx index 495cdc2..2e163ca 100644 --- a/src/asyncWithLDProvider.test.tsx +++ b/src/asyncWithLDProvider.test.tsx @@ -39,7 +39,14 @@ const renderWithConfig = async (config: AsyncProviderConfig) => { const { getByText } = render( - {(value) => Received: {`Flags: ${JSON.stringify(value.flags)}.\nError: ${value.error?.message}.`}} + {(value) => ( + + Received:{' '} + {`Flags: ${JSON.stringify(value.flags)}. + Error: ${value.error?.message}. + ldClient: ${value.ldClient ? 'initialized' : 'undefined'}.`} + + )} , ); @@ -318,6 +325,11 @@ describe('asyncWithLDProvider', () => { expect(receivedNode).toHaveTextContent('{"testFlag":true,"anotherTestFlag":true}'); }); + test('internal ldClient state should be initialised', async () => { + const receivedNode = await renderWithConfig({ clientSideID, context, options }); + expect(receivedNode).toHaveTextContent('ldClient: initialized'); + }); + test('ldClient is initialised correctly with target flags', async () => { options = { ...wrapperOptions }; const flags = { 'test-flag': false }; diff --git a/src/asyncWithLDProvider.tsx b/src/asyncWithLDProvider.tsx index 2044783..5ad0095 100644 --- a/src/asyncWithLDProvider.tsx +++ b/src/asyncWithLDProvider.tsx @@ -52,6 +52,7 @@ export default async function asyncWithLDProvider(config: AsyncProviderConfig) { const [ldData, setLDData] = useState(() => ({ unproxiedFlags: initialFlags, ...getFlagsProxy(ldClient, initialFlags, reactOptions, targetFlags), + ldClient, error, }));