drawer.test.tsx 903 B

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