drawer.test.tsx 1010 B

12345678910111213141516171819202122232425262728293031
  1. /* eslint-disable import/no-extraneous-dependencies */
  2. /* eslint-disable no-undef */
  3. import React from 'react';
  4. import { render, cleanup } from '@testing-library/react';
  5. import Drawer from '../components/Drawer';
  6. describe('Drawer component', () => {
  7. afterEach(cleanup);
  8. test('drawer content', () => {
  9. const { getByText } = render(<Drawer>content</Drawer>);
  10. expect(getByText('content').textContent).toBe('content');
  11. });
  12. test('close drawer', () => {
  13. const { getByTestId } = render(<Drawer>content</Drawer>);
  14. const ele = getByTestId('drawer');
  15. const style = window.getComputedStyle(ele as HTMLElement) as { [key: string]: any };
  16. expect(style.transform).toBe('translate(0,267px)');
  17. });
  18. test('open drawer', () => {
  19. const { getByTestId } = render(<Drawer open>content</Drawer>);
  20. const ele = getByTestId('drawer');
  21. const style = window.getComputedStyle(ele as HTMLElement) as { [key: string]: any };
  22. expect(style.transform).toBe('translate(0,0)');
  23. });
  24. });