Skip to content

Commit

Permalink
fix: add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
heiyu4585 committed Jan 9, 2023
1 parent 8aae348 commit 4143c57
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions tests/CSSMotion.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,14 @@ describe('CSSMotion', () => {
);

it('leaveClassName should add to dom', () => {
const genMotion = ({ visible }) => {
const genMotion = (props) => {
const {visible,leavedClassName} = props
return (
<CSSMotion
motionName="transition"
visible={visible}
removeOnLeave={false}
leavedClassName={'removed'}
leavedClassName={leavedClassName}
>
{({ style, className }) => {
return (
Expand All @@ -188,14 +189,27 @@ describe('CSSMotion', () => {
});

expect(container.querySelector('.motion-box')).toBeTruthy();
rerender(genMotion({ visible: false }));
rerender(genMotion({ visible: false,leavedClassName:'removed'}));
act(() => {
jest.runAllTimers();
});

fireEvent.transitionEnd(container.querySelector('.motion-box'));

expect(container.querySelector('.motion-box')).toHaveClass('removed');

rerender(genMotion({ visible: true }));
act(() => {
jest.runAllTimers();
});
rerender(genMotion({ visible: false }));
act(() => {
jest.runAllTimers();
});

fireEvent.transitionEnd(container.querySelector('.motion-box'));
expect(container.querySelector('.motion-box')?.classList.contains('removed')).toBeFalsy();

});

it('stop transition if config motion to false', () => {
Expand Down

0 comments on commit 4143c57

Please sign in to comment.