|
| 1 | +/* eslint-disable |
| 2 | + react/no-render-return-value, max-classes-per-file, |
| 3 | + react/prefer-stateless-function, react/no-multi-comp |
| 4 | +*/ |
| 5 | +import React from 'react'; |
| 6 | +import { act } from 'react-dom/test-utils'; |
| 7 | +import classNames from 'classnames'; |
| 8 | +import { render, fireEvent } from '@testing-library/react'; |
| 9 | +// import type { CSSMotionProps } from '../src/CSSMotion'; |
| 10 | +import { genCSSMotion } from '../src/CSSMotion'; |
| 11 | +// import RefCSSMotion, { genCSSMotion } from '../src/CSSMotion'; |
| 12 | +// import ReactDOM from 'react-dom'; |
| 13 | + |
| 14 | +describe('StrictMode', () => { |
| 15 | + const CSSMotion = genCSSMotion({ |
| 16 | + transitionSupport: true, |
| 17 | + }); |
| 18 | + |
| 19 | + beforeEach(() => { |
| 20 | + jest.useFakeTimers(); |
| 21 | + }); |
| 22 | + |
| 23 | + afterEach(() => { |
| 24 | + jest.clearAllTimers(); |
| 25 | + jest.useRealTimers(); |
| 26 | + }); |
| 27 | + |
| 28 | + it('motion should end', () => { |
| 29 | + const ref = React.createRef(); |
| 30 | + |
| 31 | + const { container } = render( |
| 32 | + <React.StrictMode> |
| 33 | + <CSSMotion motionName="transition" ref={ref} motionAppear visible> |
| 34 | + {({ style, className }) => { |
| 35 | + return ( |
| 36 | + <div |
| 37 | + style={style} |
| 38 | + className={classNames('motion-box', className)} |
| 39 | + /> |
| 40 | + ); |
| 41 | + }} |
| 42 | + </CSSMotion> |
| 43 | + </React.StrictMode>, |
| 44 | + ); |
| 45 | + |
| 46 | + const node = container.querySelector('.motion-box'); |
| 47 | + expect(node).toHaveClass('transition-appear', 'transition-appear-start'); |
| 48 | + |
| 49 | + // Active |
| 50 | + act(() => { |
| 51 | + jest.runAllTimers(); |
| 52 | + }); |
| 53 | + expect(node).not.toHaveClass('transition-appear-start'); |
| 54 | + expect(node).toHaveClass('transition-appear-active'); |
| 55 | + |
| 56 | + // Trigger End |
| 57 | + fireEvent.transitionEnd(node); |
| 58 | + expect(node).not.toHaveClass('transition-appear'); |
| 59 | + |
| 60 | + expect(ref.current).toBe(node); |
| 61 | + }); |
| 62 | +}); |
0 commit comments