Skip to content

Commit

Permalink
test: add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Apr 18, 2023
1 parent 60258fd commit 769bfac
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions tests/CSSMotion.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
react/no-render-return-value, max-classes-per-file,
react/prefer-stateless-function, react/no-multi-comp
*/
import { fireEvent, render } from '@testing-library/react';
import classNames from 'classnames';
import React from 'react';
import ReactDOM from 'react-dom';
import { act } from 'react-dom/test-utils';
import classNames from 'classnames';
import { render, fireEvent } from '@testing-library/react';
import type { CSSMotionProps } from '../src';
import { Provider } from '../src';
import RefCSSMotion, { genCSSMotion } from '../src/CSSMotion';
import ReactDOM from 'react-dom';

describe('CSSMotion', () => {
const CSSMotion = genCSSMotion({
Expand Down Expand Up @@ -482,6 +482,9 @@ describe('CSSMotion', () => {
});

it('MotionProvider to disable motion', () => {
const onAppearPrepare = jest.fn();
const onAppearStart = jest.fn();

const Demo = ({
motion,
visible,
Expand All @@ -495,6 +498,9 @@ describe('CSSMotion', () => {
visible={visible}
removeOnLeave={false}
leavedClassName="hidden"
motionAppear
onAppearPrepare={onAppearPrepare}
onAppearStart={onAppearStart}
>
{({ style, className }) => (
<div
Expand All @@ -509,6 +515,13 @@ describe('CSSMotion', () => {
const { container, rerender } = render(<Demo motion={false} visible />);
expect(container.querySelector('.motion-box')).toBeTruthy();

act(() => {
jest.runAllTimers();
});

expect(onAppearPrepare).toHaveBeenCalled();
expect(onAppearStart).not.toHaveBeenCalled();

// hide immediately since motion is disabled
rerender(<Demo motion={false} visible={false} />);
expect(container.querySelector('.hidden')).toBeTruthy();
Expand Down

0 comments on commit 769bfac

Please sign in to comment.