Skip to content

Commit 37c3028

Browse files
committed
Improve colors test
1 parent 8d67a35 commit 37c3028

File tree

1 file changed

+21
-1
lines changed
  • packages/react-native-reanimated/src/common/processors/__tests__

1 file changed

+21
-1
lines changed

packages/react-native-reanimated/src/common/processors/__tests__/colors.test.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { ReanimatedError } from '../../errors';
33
import { ERROR_MESSAGES, processColor, processColorsInProps } from '../colors';
44

5-
describe(processColor, () => {
5+
describe(processColorsInProps, () => {
66
describe('properly converts colors in props', () => {
77
test.each([
88
['backgroundColor', 'red', 0xff0000ff],
@@ -23,6 +23,7 @@ describe(processColor, () => {
2323
['overlayColor', 'hsla(360, 100%, 50%, 0.75)', 0xff0000bf],
2424
['tintColor', 'hsl(180, 100%, 25%)', 0x007f80ff],
2525
])('converts %p with value %p to %p', (key, value, expected) => {
26+
// convert from RGBA to ARGB format
2627
const argb = ((expected << 24) | (expected >>> 8)) >>> 0;
2728
const props = { [key]: value };
2829

@@ -46,6 +47,25 @@ describe(processColor, () => {
4647
expect(props).toEqual({ [key]: value });
4748
});
4849
});
50+
});
51+
52+
describe(processColor, () => {
53+
describe('properly converts colors', () => {
54+
test.each([
55+
['red', 0xff0000ff],
56+
['rgb(255, 200, 0)', 0xffc800ff],
57+
['rgba(50, 100, 150, 0.6)', 0x32649699],
58+
['#34a', 0x3344aaff],
59+
['hsl(240, 100%, 50%)', 0x0000ffff],
60+
['hsla(120, 50%, 50%, 0.5)', 0x40bf4080],
61+
['hwb(0, 0%, 0%)', 0xff0000ff],
62+
['transparent', null],
63+
])('converts %p to %p', (value, expected) => {
64+
// convert from RGBA to ARGB format if not null
65+
const argb = expected && ((expected << 24) | (expected >>> 8)) >>> 0;
66+
expect(processColor(value)).toEqual(argb);
67+
});
68+
});
4969

5070
describe('throws an error for invalid color values', () => {
5171
test.each([

0 commit comments

Comments
 (0)