@navinc/base-react-components
Version:
Nav's Pattern Library
39 lines (33 loc) • 1.23 kB
JavaScript
import { screen, render } from '@testing-library/react'
import { Radio } from './radio.js'
import * as utils from '@navinc/utils'
describe('<Radio />', () => {
describe('componentDidMount', () => {
it('calls focusWithoutScroll if autoFocus is true (inaccessible)', () => {
const spy = jest.spyOn(utils, 'focusWithoutScroll')
// eslint-disable-next-line jsx-a11y/no-autofocus
render(<Radio autoFocus />)
expect(spy).toHaveBeenCalled()
spy.mockRestore()
})
it('doesnt call focusWithoutScroll if autoFocus is undefined', () => {
const spy = jest.spyOn(utils, 'focusWithoutScroll')
render(<Radio />)
expect(spy).not.toHaveBeenCalled()
spy.mockRestore()
})
})
describe('render', () => {
it('renders CopyLabel if provided a string label', () => {
const expected = 'abcd'
render(<Radio label={expected} />)
expect(screen.getByText(expected)).toBeInTheDocument()
})
it('renders a DivLabel if provided a component', () => {
const expected = '123'
const Component = () => <div>{expected}</div>
render(<Radio label={<Component />} />)
expect(screen.getByText(expected)).toBeInTheDocument()
})
})
})