@navinc/base-react-components
Version:
Nav's Pattern Library
37 lines (29 loc) • 1.11 kB
JavaScript
import React from 'react'
import { render, waitFor } from '@testing-library/react'
import * as launchdarkly from 'launchdarkly-js-client-sdk'
import { LaunchDarklyProvider } from './use-launchdarkly.js'
const LaunchDarklyProviderWithContent = () => (
<LaunchDarklyProvider
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', () => {
const { getByTestId } = render(<LaunchDarklyProviderWithContent />)
expect(getByTestId('ld-loading-content'))
})
it('should render children after initializing', () => {
jest.spyOn(launchdarkly, 'initialize').mockReturnValue({
waitForInitialization: () => Promise.resolve(),
allFlags: () => ['flag-1', 'flag-2'],
})
const { getByTestId } = render(<LaunchDarklyProviderWithContent />)
waitFor(() => expect(getByTestId('ld-content')))
})
})
})