Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/react-native-reanimated/src/jestUtils/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

import type { WorkletFunction } from 'react-native-worklets';

/**
* Converts any callback function to a mock worklet function for testing
* purposes. This function simulates a worklet by adding the required internal
* properties.
*
* @param callback - Optional callback function to wrap as a worklet. If not
* provided, returns an empty worklet.
* @returns A mock worklet function with the required worklet properties.
*/
export const worklet = <Args extends unknown[] = [], ReturnValue = void>(
callback?: (...args: Args) => ReturnValue
): WorkletFunction<Args, ReturnValue> => {
const fn = (callback ?? (() => undefined)) as WorkletFunction<
Args,
ReturnValue
>;
fn.__workletHash = Math.random();
fn.__closure = {};
return fn;
};
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
/* eslint-disable @typescript-eslint/no-namespace */
'use strict';

import type React from 'react';
import type { ReactTestInstance } from 'react-test-renderer';

import { IS_JEST, logger, ReanimatedError } from './common';
import { IS_JEST, logger, ReanimatedError } from '../common';
import type {
AnimatedComponentProps,
AnimatedProps,
IAnimatedComponentInternal,
InitialComponentProps,
} from './createAnimatedComponent/commonTypes';
import type { DefaultStyle } from './hook/commonTypes';
} from '../createAnimatedComponent/commonTypes';
import type { DefaultStyle } from '../hook/commonTypes';

declare global {
namespace jest {
Expand Down Expand Up @@ -353,3 +354,6 @@ export const getAnimatedStyle = (component: ReactTestInstance) => {
component as unknown as TestComponent
);
};

/** @knipIgnore */
export { worklet } from './common';
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ export function setUpTests() {
export function getAnimatedStyle() {
// NOOP
}

export { worklet } from './common';
Loading