Skip to content

Commit

Permalink
chore: more refs (#63)
Browse files Browse the repository at this point in the history
* chore: more refs

* test: more test
  • Loading branch information
zombieJ authored Feb 11, 2025
1 parent b32f8f8 commit df004ab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/CSSMotion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import { getTransitionName, supportTransition } from './util/motion';

export interface CSSMotionRef {
nativeElement: HTMLElement;
inMotion: () => boolean;
inMotion: boolean;
enableMotion: boolean;
}

export type CSSMotionConfig =
Expand Down Expand Up @@ -172,9 +173,11 @@ export function genCSSMotion(config: CSSMotionConfig) {
},
inMotion: {
enumerable: true,
get: () => {
return () => getStatus() !== STATUS_NONE;
},
get: () => getStatus() !== STATUS_NONE,
},
enableMotion: {
enumerable: true,
get: () => supportMotion,
},
});
return obj;
Expand Down
6 changes: 4 additions & 2 deletions tests/StrictMode.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,24 @@ describe('StrictMode', () => {
</React.StrictMode>,
);

expect(ref.current.enableMotion).toBeTruthy();

const node = container.querySelector('.motion-box');
expect(node).toHaveClass('transition-appear', 'transition-appear-start');

// Active
act(() => {
jest.runAllTimers();
});
expect(ref.current.inMotion()).toBeTruthy();
expect(ref.current.inMotion).toBeTruthy();
expect(node).not.toHaveClass('transition-appear-start');
expect(node).toHaveClass('transition-appear-active');

// Trigger End
fireEvent.transitionEnd(node);
expect(node).not.toHaveClass('transition-appear');

expect(ref.current.inMotion()).toBeFalsy();
expect(ref.current.inMotion).toBeFalsy();
expect(ref.current.nativeElement).toBe(node);
});
});

0 comments on commit df004ab

Please sign in to comment.