UNPKG

@navinc/base-react-components

Version:
39 lines (32 loc) 1.22 kB
import { screen } from '@testing-library/react' import { renderWithContext } from './tests/with-app-context.js' import * as utils from '@navinc/utils' import { Input } from './input.js' describe('Base Components: Input', () => { describe('componentDidMount', () => { beforeEach(() => { jest.spyOn(utils, 'focusWithoutScroll') }) it('calls focusWithoutScroll if autoFocus is true (inaccessible)', () => { // eslint-disable-next-line jsx-a11y/no-autofocus renderWithContext(<Input autoFocus />) expect(utils.focusWithoutScroll).toHaveBeenCalled() }) it('doesnt call focusWithoutScroll if autoFocus is undefined', () => { renderWithContext(<Input />) expect(utils.focusWithoutScroll).not.toHaveBeenCalled() }) }) describe('render', () => { it('renders errors if there are any', () => { const expected = 'error test' renderWithContext(<Input errors={[expected]} />) expect(screen.getByText(expected)).toBeInTheDocument() }) it('doesnt render errors if there arent any', () => { const expected = 'error test' renderWithContext(<Input />) expect(() => screen.getByText(expected)).toThrow() }) }) })