jest tests for PlatformColor support (#54458)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/54458

## Changelog:

[General] [Added] jest tests for PlatformColor support

Reviewed By: yungsters

Differential Revision: D86547464

fbshipit-source-id: b89e8d30c20dd0a507b312cf1d813891e6ccb077
This commit is contained in:
Zeya Peng authored and meta-codesync[bot] committed 2025-11-17 08:24:39 -08:00
1 parent efd2f679f2
commit cbbba7b9a5
1 file changed
+31 -2
@@ -8,12 +8,16 @@
* @format
*/
import type {InterpolationConfigType} from '../nodes/AnimatedInterpolation';
import type {
InterpolationConfigSupportedOutputType,
InterpolationConfigType,
} from '../nodes/AnimatedInterpolation';
import {PlatformColor} from '../../../Libraries/StyleSheet/PlatformColorValueTypes';
import Easing from '../Easing';
import AnimatedInterpolation from '../nodes/AnimatedInterpolation';
function createInterpolation<T: number | string>(
function createInterpolation<T: InterpolationConfigSupportedOutputType>(
config: InterpolationConfigType<T>,
): number => T {
let parentValue = null;
@@ -360,6 +364,31 @@ describe('Interpolation', () => {
expect(interpolation(2 / 3)).toBe('rgba(0, 0, 0, 0.667)');
});
it('should work with PlatformColor', () => {
jest.spyOn(console, 'warn').mockImplementationOnce(() => {});
const interpolation = createInterpolation({
inputRange: [0, 1],
outputRange: [
PlatformColor('@android:color/white'),
PlatformColor('@android:color/darker_gray'),
],
});
// NativeColorValue is deferred to the native side to interpolate
expect(interpolation(0)).toStrictEqual(
PlatformColor('@android:color/white'),
);
expect(interpolation(2 / 3)).toStrictEqual(
PlatformColor('@android:color/white'),
);
expect(console.warn).toBeCalledWith(
'PlatformColor interpolation should happen natively, here we fallback to the closest color',
);
expect(interpolation(1)).toStrictEqual(
PlatformColor('@android:color/darker_gray'),
);
});
it.each([
['radians', ['1rad', '2rad'], [1, 2]],
['degrees', ['90deg', '180deg'], [Math.PI / 2, Math.PI]],