drawer.test.tsx 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  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 {
  16. [key: string]: any;
  17. };
  18. expect(style.transform).toBe('translate(0,267px)');
  19. });
  20. test('open drawer', () => {
  21. const { getByTestId } = render(<Drawer open>content</Drawer>);
  22. const ele = getByTestId('drawer');
  23. const style = window.getComputedStyle(ele as HTMLElement) as {
  24. [key: string]: any;
  25. };
  26. expect(style.transform).toBe('translate(0,0)');
  27. });
  28. });