inputBox.test.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* eslint-disable import/no-extraneous-dependencies */
  2. /* eslint-disable no-undef */
  3. import React from 'react';
  4. import { render, cleanup, fireEvent } from '@testing-library/react';
  5. import '@testing-library/jest-dom';
  6. import InputBox from '../components/InputBox';
  7. describe('Input Box component', () => {
  8. afterEach(cleanup);
  9. test('input element', () => {
  10. const { container } = render(<InputBox />);
  11. const inputNode = container.querySelector('input') as HTMLElement;
  12. expect(inputNode.tagName).toBe('INPUT');
  13. });
  14. test('textarea element', () => {
  15. const { container } = render(<InputBox variant="multiline" />);
  16. const textAreaNode = container.querySelector('TextArea') as HTMLElement;
  17. expect(textAreaNode.tagName).toBe('TEXTAREA');
  18. });
  19. test('onChange event', () => {
  20. const { container } = render(<InputBox />);
  21. const inputNode = container.querySelector('input') as HTMLInputElement;
  22. fireEvent.change(inputNode, { target: { value: 'text' } });
  23. expect(inputNode.value).toBe('text');
  24. });
  25. test('check disabled input', () => {
  26. const handleChange = jest.fn();
  27. const { getByTestId } = render(
  28. <InputBox disabled onChange={handleChange} />
  29. );
  30. fireEvent.change(getByTestId('input'), { target: { value: 'text' } });
  31. expect(handleChange).toBeCalledTimes(0);
  32. expect(getByTestId('input')).toBeDisabled();
  33. });
  34. });