@navinc/base-react-components
Version:
Nav's Pattern Library
41 lines (33 loc) • 1.27 kB
JavaScript
import React from 'react'
import { render, withAppContext } from '../tests/with-app-context.js'
import * as utils from '@navinc/utils'
import { InputField as RawInputField } from './input.js'
const InputField = withAppContext(RawInputField)
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
render(<InputField autoFocus />)
expect(utils.focusWithoutScroll).toHaveBeenCalled()
})
it('doesnt call focusWithoutScroll if autoFocus is undefined', () => {
render(<InputField />)
expect(utils.focusWithoutScroll).not.toHaveBeenCalled()
})
})
describe('render', () => {
it('renders errors if there are any', () => {
const expected = 'error test'
const { getByText } = render(<InputField errors={[expected]} />)
expect(getByText(expected)).toBeTruthy()
})
it('doesnt render errors if there arent any', () => {
const expected = 'error test'
const { getByText } = render(<InputField />)
expect(() => getByText(expected)).toThrow()
})
})
})