From df004ab984548a98533fc90f33fd0fc9920da114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E7=88=B1=E5=90=83=E7=99=BD=E8=90=9D?= =?UTF-8?q?=E5=8D=9C?= Date: Tue, 11 Feb 2025 15:42:26 +0800 Subject: [PATCH] chore: more refs (#63) * chore: more refs * test: more test --- src/CSSMotion.tsx | 11 +++++++---- tests/StrictMode.spec.tsx | 6 ++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/CSSMotion.tsx b/src/CSSMotion.tsx index f0c468c..d1243bd 100644 --- a/src/CSSMotion.tsx +++ b/src/CSSMotion.tsx @@ -18,7 +18,8 @@ import { getTransitionName, supportTransition } from './util/motion'; export interface CSSMotionRef { nativeElement: HTMLElement; - inMotion: () => boolean; + inMotion: boolean; + enableMotion: boolean; } export type CSSMotionConfig = @@ -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; diff --git a/tests/StrictMode.spec.tsx b/tests/StrictMode.spec.tsx index 10e955d..0790e1c 100644 --- a/tests/StrictMode.spec.tsx +++ b/tests/StrictMode.spec.tsx @@ -43,6 +43,8 @@ describe('StrictMode', () => { , ); + expect(ref.current.enableMotion).toBeTruthy(); + const node = container.querySelector('.motion-box'); expect(node).toHaveClass('transition-appear', 'transition-appear-start'); @@ -50,7 +52,7 @@ describe('StrictMode', () => { 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'); @@ -58,7 +60,7 @@ describe('StrictMode', () => { 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); }); });