|
2 | 2 | react/no-render-return-value, max-classes-per-file, |
3 | 3 | react/prefer-stateless-function, react/no-multi-comp |
4 | 4 | */ |
5 | | -import { fireEvent, render } from '@testing-library/react'; |
| 5 | +import { act, fireEvent, render } from '@testing-library/react'; |
6 | 6 | import classNames from 'classnames'; |
7 | 7 | import React from 'react'; |
8 | 8 | import ReactDOM from 'react-dom'; |
9 | | -import { act } from 'react-dom/test-utils'; |
10 | 9 | import type { CSSMotionProps } from '../src'; |
11 | 10 | import { Provider } from '../src'; |
12 | 11 | import RefCSSMotion, { genCSSMotion } from '../src/CSSMotion'; |
@@ -342,6 +341,60 @@ describe('CSSMotion', () => { |
342 | 341 | return <div {...props} />; |
343 | 342 | }), |
344 | 343 | ); |
| 344 | + |
| 345 | + it('not warning on StrictMode', () => { |
| 346 | + const onLeaveEnd = jest.fn(); |
| 347 | + const errorSpy = jest.spyOn(console, 'error'); |
| 348 | + |
| 349 | + const renderDemo = (visible: boolean) => ( |
| 350 | + <React.StrictMode> |
| 351 | + <CSSMotion |
| 352 | + motionName="transition" |
| 353 | + motionDeadline={1000} |
| 354 | + onLeaveEnd={onLeaveEnd} |
| 355 | + visible={visible} |
| 356 | + motionAppear={false} |
| 357 | + motionLeave={true} |
| 358 | + > |
| 359 | + {({ style, className }) => ( |
| 360 | + <div |
| 361 | + style={style} |
| 362 | + className={classNames('motion-box', className)} |
| 363 | + /> |
| 364 | + )} |
| 365 | + </CSSMotion> |
| 366 | + </React.StrictMode> |
| 367 | + ); |
| 368 | + |
| 369 | + const { rerender, container } = render(renderDemo(true)); |
| 370 | + act(() => { |
| 371 | + jest.advanceTimersByTime(100000); |
| 372 | + }); |
| 373 | + |
| 374 | + // Leave |
| 375 | + rerender(renderDemo(false)); |
| 376 | + act(() => { |
| 377 | + jest.advanceTimersByTime(500); |
| 378 | + }); |
| 379 | + |
| 380 | + // Motion end |
| 381 | + fireEvent.transitionEnd( |
| 382 | + container.querySelector('.transition-leave-active'), |
| 383 | + ); |
| 384 | + act(() => { |
| 385 | + jest.advanceTimersByTime(100); |
| 386 | + }); |
| 387 | + |
| 388 | + // Another timeout |
| 389 | + act(() => { |
| 390 | + jest.advanceTimersByTime(1000); |
| 391 | + }); |
| 392 | + |
| 393 | + expect(onLeaveEnd).toHaveBeenCalledTimes(1); |
| 394 | + expect(errorSpy).not.toHaveBeenCalled(); |
| 395 | + |
| 396 | + errorSpy.mockRestore(); |
| 397 | + }); |
345 | 398 | }); |
346 | 399 |
|
347 | 400 | it('not crash when no children', () => { |
|
0 commit comments