File tree Expand file tree Collapse file tree 3 files changed +33
-3
lines changed
packages/react-native-reanimated/src/jestUtils Expand file tree Collapse file tree 3 files changed +33
-3
lines changed Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ import type { WorkletFunction } from 'react-native-worklets' ;
4+
5+ /**
6+ * Converts any callback function to a mock worklet function for testing
7+ * purposes. This function simulates a worklet by adding the required internal
8+ * properties.
9+ *
10+ * @param callback - Optional callback function to wrap as a worklet. If not
11+ * provided, returns an empty worklet.
12+ * @returns A mock worklet function with the required worklet properties.
13+ */
14+ export const worklet = < Args extends unknown [ ] = [ ] , ReturnValue = void > (
15+ callback ?: ( ...args : Args ) => ReturnValue
16+ ) : WorkletFunction < Args , ReturnValue > => {
17+ const fn = ( callback ?? ( ( ) => undefined ) ) as WorkletFunction <
18+ Args ,
19+ ReturnValue
20+ > ;
21+ fn . __workletHash = Math . random ( ) ;
22+ fn . __closure = { } ;
23+ return fn ;
24+ } ;
Original file line number Diff line number Diff line change 11/* eslint-disable @typescript-eslint/no-namespace */
22'use strict' ;
33
4+ import type React from 'react' ;
45import type { ReactTestInstance } from 'react-test-renderer' ;
56
6- import { IS_JEST , logger , ReanimatedError } from './common' ;
7+ import { IS_JEST , logger , ReanimatedError } from '.. /common' ;
78import type {
89 AnimatedComponentProps ,
910 AnimatedProps ,
1011 IAnimatedComponentInternal ,
1112 InitialComponentProps ,
12- } from './createAnimatedComponent/commonTypes' ;
13- import type { DefaultStyle } from './hook/commonTypes' ;
13+ } from '.. /createAnimatedComponent/commonTypes' ;
14+ import type { DefaultStyle } from '.. /hook/commonTypes' ;
1415
1516declare global {
1617 namespace jest {
@@ -353,3 +354,6 @@ export const getAnimatedStyle = (component: ReactTestInstance) => {
353354 component as unknown as TestComponent
354355 ) ;
355356} ;
357+
358+ /** @knipIgnore */
359+ export { worklet } from './common' ;
Original file line number Diff line number Diff line change @@ -22,3 +22,5 @@ export function setUpTests() {
2222export function getAnimatedStyle ( ) {
2323 // NOOP
2424}
25+
26+ export { worklet } from './common' ;
You can’t perform that action at this time.
0 commit comments