UNPKG

@navinc/base-react-components

Version:
36 lines (28 loc) 1.09 kB
import { screen, render, waitFor } from '@testing-library/react' import * as launchdarkly from 'launchdarkly-js-client-sdk' import { LaunchDarklyProvider } from './use-launchdarkly.js' const LaunchDarklyProviderWithContent = () => ( <LaunchDarklyProvider context={{ kind: 'user', key: 'test' }} clientSideID="123" LoadingContent={() => <p data-testid="ld-loading-content">Loading</p>} > <p data-testid="ld-content">content</p> </LaunchDarklyProvider> ) describe('LaunchDarkly', () => { describe('LaunchDarklyProvider', () => { it('should render loading content', () => { render(<LaunchDarklyProviderWithContent />) expect(screen.getByTestId('ld-loading-content')) }) it('should render children after initializing', async () => { jest.spyOn(launchdarkly, 'initialize').mockReturnValue({ waitForInitialization: () => Promise.resolve(), allFlags: () => ['flag-1', 'flag-2'], }) render(<LaunchDarklyProviderWithContent />) await waitFor(() => expect(screen.getByTestId('ld-content'))) }) }) })