UNPKG

@navinc/base-react-components

Version:
40 lines (34 loc) 1.38 kB
import React from 'react' import { render } from '@testing-library/react' import { Radio } from './radio.js' import * as focusWithoutScrollModule from '@navinc/utils/cjs/focus-without-scroll.js' describe('<Radio />', () => { describe('componentDidMount', () => { it('calls focusWithoutScroll if autoFocus is true (inaccessible)', () => { const spy = jest.spyOn(focusWithoutScrollModule, 'default') // eslint-disable-next-line jsx-a11y/no-autofocus render(<Radio autoFocus />) expect(focusWithoutScrollModule.default).toHaveBeenCalled() spy.mockRestore() }) it('doesnt call focusWithoutScroll if autoFocus is undefined', () => { const spy = jest.spyOn(focusWithoutScrollModule, 'default') render(<Radio />) expect(focusWithoutScrollModule.default).not.toHaveBeenCalled() spy.mockRestore() }) }) describe('render', () => { it('renders CopyLabel if provided a string label', () => { const expected = 'abcd' const { getByText } = render(<Radio label={expected} />) expect(getByText(expected)).toBeTruthy() }) it('renders a DivLabel if provided a component', () => { const expected = '123' const Component = () => <div>{expected}</div> const { getByText } = render(<Radio label={<Component />} />) expect(getByText(expected)).toBeTruthy() }) }) })