@navinc/base-react-components
Version:
Nav's Pattern Library
67 lines (56 loc) • 1.86 kB
JavaScript
import { screen, render } from '@testing-library/react'
import WaitForDependencies from './wait-for-dependencies.js'
describe('<WaitForDependencies />', () => {
it('renders children if all hasDependencyProps are true', () => {
render(
<WaitForDependencies hasDependencyProps={[true, true]}>
<div>yoyo</div>
</WaitForDependencies>
)
expect(screen.getByText('yoyo'))
})
it('doesnt render children if one of hasDependencyProps is false', () => {
render(
<WaitForDependencies hasDependencyProps={[true, false]}>
<div>yoyo</div>
</WaitForDependencies>
)
expect(screen.queryByText('yoyo')).not.toBeInTheDocument()
})
it(
'renders LoadingContent if one of the hasDependencyProps is false' +
' and one of loadingProps is true and LoadingContent is provided',
() => {
render(
<WaitForDependencies
hasDependencyProps={[true, false]}
loadingProps={[false, true]}
LoadingContent={<div>loading</div>}
/>
)
expect(screen.getByText('loading'))
}
)
it(
'doesnt render LoadingContent if one of the hasDependencyProps is false' +
' and one of loadingProps is true and LoadingContent is not provided',
() => {
render(<WaitForDependencies hasDependencyProps={[true, false]} loadingProps={[false, true]} />)
expect(screen.queryByText('loading')).not.toBeInTheDocument()
}
)
it(
'renders ErrorContent if one of the hasDependencyProps is false,' +
' all of loadingProps are false, and ErrorContent is provided',
() => {
render(
<WaitForDependencies
hasDependencyProps={[true, false]}
loadingProps={[false, false]}
ErrorContent={<div>error</div>}
/>
)
expect(screen.getByText('error'))
}
)
})