@navinc/base-react-components
Version:
Nav's Pattern Library
35 lines • 1.53 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { beforeEach, describe, expect, it, vi } from 'vitest';
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(() => {
vi.spyOn(utils, 'focusWithoutScroll');
});
it('calls focusWithoutScroll if autoFocus is true (inaccessible)', () => {
// eslint-disable-next-line jsx-a11y/no-autofocus
renderWithContext(_jsx(Input, { autoFocus: true }));
expect(utils.focusWithoutScroll).toHaveBeenCalled();
});
it('doesnt call focusWithoutScroll if autoFocus is undefined', () => {
renderWithContext(_jsx(Input, {}));
expect(utils.focusWithoutScroll).not.toHaveBeenCalled();
});
});
describe('render', () => {
it('renders errors if there are any', () => {
const expected = 'error test';
renderWithContext(_jsx(Input, { errors: [expected] }));
expect(screen.getByText(expected)).toBeInTheDocument();
});
it('doesnt render errors if there arent any', () => {
const expected = 'error test';
renderWithContext(_jsx(Input, {}));
expect(() => screen.getByText(expected)).toThrow();
});
});
});
//# sourceMappingURL=input.spec.js.map