@navinc/base-react-components
Version:
Nav's Pattern Library
37 lines • 1.67 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { describe, expect, it, vi } from 'vitest';
import { screen } from '@testing-library/react';
import { Radio } from './radio.js';
import * as utils from '@navinc/utils';
import { renderWithContext } from './tests/with-app-context.js';
describe('<Radio />', () => {
describe('componentDidMount', () => {
it('calls focusWithoutScroll if autoFocus is true (inaccessible)', () => {
const spy = vi.spyOn(utils, 'focusWithoutScroll');
// eslint-disable-next-line jsx-a11y/no-autofocus
renderWithContext(_jsx(Radio, { autoFocus: true }));
expect(spy).toHaveBeenCalled();
spy.mockRestore();
});
it('doesnt call focusWithoutScroll if autoFocus is undefined', () => {
const spy = vi.spyOn(utils, 'focusWithoutScroll');
renderWithContext(_jsx(Radio, {}));
expect(spy).not.toHaveBeenCalled();
spy.mockRestore();
});
});
describe('render', () => {
it('renders CopyLabel if provided a string label', () => {
const expected = 'abcd';
renderWithContext(_jsx(Radio, { label: expected }));
expect(screen.getByText(expected)).toBeInTheDocument();
});
it('renders a DivLabel if provided a component', () => {
const expected = '123';
const Component = () => _jsx("div", { children: expected });
renderWithContext(_jsx(Radio, { label: _jsx(Component, {}) }));
expect(screen.getByText(expected)).toBeInTheDocument();
});
});
});
//# sourceMappingURL=radio.spec.js.map