Skip to content
Closed
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

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @format
*/

'use strict';
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';

const flattenStyle = require('../flattenStyle').default;
const StyleSheet = require('../StyleSheet').default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* @format
*/

import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
import processAspectRatio from '../processAspectRatio';

describe('processAspectRatio', () => {
Expand Down Expand Up @@ -41,9 +42,15 @@ describe('processAspectRatio', () => {
});

it('should not accept invalid formats', () => {
expect(() => processAspectRatio('0a')).toThrowErrorMatchingSnapshot();
expect(() => processAspectRatio('1 / 1 1')).toThrowErrorMatchingSnapshot();
expect(() => processAspectRatio('auto 1/1')).toThrowErrorMatchingSnapshot();
expect(() => processAspectRatio('0a')).toThrow(
'aspectRatio must either be a number, a ratio string or `auto`. You passed: 0a',
);
expect(() => processAspectRatio('1 / 1 1')).toThrow(
'aspectRatio must either be a number, a ratio string or `auto`. You passed: 1 / 1 1',
);
expect(() => processAspectRatio('auto 1/1')).toThrow(
'aspectRatio must either be a number, a ratio string or `auto`. You passed: auto 1/1',
);
});

it('should ignore non string falsy types', () => {
Expand All @@ -57,8 +64,12 @@ describe('processAspectRatio', () => {
it('should not accept non string truthy types', () => {
const invalidThings = [() => {}, [1, 2, 3], {}];
for (const thing of invalidThings) {
// $FlowExpectedError[incompatible-type]
expect(() => processAspectRatio(thing)).toThrowErrorMatchingSnapshot();
expect(() =>
// $FlowExpectedError[incompatible-type]
processAspectRatio(thing),
).toThrow(
`aspectRatio must either be a number, a ratio string or \`auto\`. You passed: ${String(thing)}`,
);
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
* @format
*/

'use strict';

import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
import processBackgroundPosition from '../processBackgroundPosition';

describe('processBackgroundPosition', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
* @format
*/

'use strict';

import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
import processBackgroundRepeat from '../processBackgroundRepeat';

describe('processBackgroundRepeat', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
* @format
*/

'use strict';

import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
import processBackgroundSize from '../processBackgroundSize';

describe('processBackgroundSize', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

'use strict';

import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';

import type {FilterFunction} from '../StyleSheetTypes';

import processColor from '../processColor';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @format
*/

'use strict';
import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';

const processFontVariant = require('../processFontVariant').default;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/

import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';

const processTransform = require('../processTransform').default;

describe('processTransform', () => {
describe('validation', () => {
it('should accept an empty array', () => {
processTransform([]);
});

it('should accept an empty string', () => {
processTransform('');
});

it('should accept a simple valid transform', () => {
processTransform([
{scale: 0.5},
{translateX: 10},
{translateY: 20},
{rotate: '10deg'},
]);
processTransform(
'scale(0.5) translateX(10px) translateY(20px) rotate(10deg)',
);
});

it('should accept a percentage translate transform', () => {
processTransform([{translateY: '20%'}, {translateX: '10%'}]);
processTransform('translateX(10%)');
});

it('should throw on object with multiple properties', () => {
expect(() => processTransform([{scale: 0.5, translateY: 10}])).toThrow(
'You must specify exactly one property per transform object. Passed properties: {"scale":0.5,"translateY":10}',
);
});

it('should throw on invalid transform property', () => {
expect(() => processTransform([{translateW: 10}])).toThrow(
'Invalid transform translateW: {"translateW":10}',
);
expect(() => processTransform('translateW(10)')).toThrow(
'Invalid transform translateW: {"translateW":10}',
);
});

it('should throw when not passing an array to an array prop', () => {
expect(() => processTransform([{matrix: 'not-a-matrix'}])).toThrow(
'Transform with key of matrix must have an array as the value: {"matrix":"not-a-matrix"}',
);
expect(() => processTransform([{translate: 10}])).toThrow(
'Transform with key of translate must have an array as the value: {"translate":10}',
);
});

it('should accept a valid matrix', () => {
processTransform([{matrix: [1, 1, 1, 1, 1, 1, 1, 1, 1]}]);
processTransform('matrix(1, 1, 1, 1, 1, 1, 1, 1, 1)');
processTransform([
{matrix: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]},
]);
processTransform(
'matrix(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)',
);
});

it('should throw when passing a matrix of the wrong size', () => {
expect(() => processTransform([{matrix: [1, 1, 1, 1]}])).toThrow(
'Matrix transform must have a length of 9 (2d) or 16 (3d). Provided matrix has a length of 4: {"matrix":[1,1,1,1]}',
);
expect(() => processTransform('matrix(1, 1, 1, 1)')).toThrow(
'Matrix transform must have a length of 9 (2d) or 16 (3d). Provided matrix has a length of 4: {"matrix":[1,1,1,1]}',
);
});

it('should accept a valid translate', () => {
processTransform([{translate: [1, 1]}]);
processTransform('translate(1px)');
processTransform('translate(1px, 1px)');
processTransform([{translate: [1, 1, 1]}]);
});

it('should throw when passing a translate of the wrong size', () => {
expect(() => processTransform([{translate: [1]}])).toThrow(
'Transform with key translate must be an array of length 2 or 3, found 1: {"translate":[1]}',
);
expect(() => processTransform([{translate: [1, 1, 1, 1]}])).toThrow(
'Transform with key translate must be an array of length 2 or 3, found 4: {"translate":[1,1,1,1]}',
);
expect(() => processTransform('translate(1px, 1px, 1px, 1px)')).toThrow(
'Transform with key translate must be an string with 1 or 2 parameters, found 4: translate(1px, 1px, 1px, 1px)',
);
});

it('should throw when passing an invalid value to a number prop', () => {
expect(() => processTransform([{translateY: '20deg'}])).toThrow(
'Transform with key of "translateY" must be number or a percentage. Passed value: {"translateY":"20deg"}.',
);
expect(() => processTransform([{scale: {x: 10, y: 10}}])).toThrow(
'Transform with key of "scale" must be a number: {"scale":{"x":10,"y":10}}',
);
expect(() => processTransform([{perspective: []}])).toThrow(
'Transform with key of "perspective" must be a number: {"perspective":[]}',
);
});

it('should throw when passing a perspective of 0', () => {
expect(() => processTransform([{perspective: 0}])).toThrow(
'Transform with key of "perspective" cannot be zero: {"perspective":0}',
);
});

it('should accept an angle in degrees or radians', () => {
processTransform([{skewY: '10deg'}]);
processTransform('skewY(10deg)');
processTransform([{rotateX: '1.16rad'}]);
processTransform('rotateX(1.16rad)');
});

it('should throw when passing an invalid angle prop', () => {
expect(() => processTransform([{rotate: 10}])).toThrow(
'Transform with key of "rotate" must be a string: {"rotate":10}',
);
expect(() => processTransform('rotate(10)')).toThrow(
'Transform with key of "rotate" must be a string: {"rotate":10}',
);
expect(() => processTransform([{skewX: '10drg'}])).toThrow(
'Rotate transform must be expressed in degrees (deg) or radians (rad): {"skewX":"10drg"}',
);
expect(() => processTransform('skewX(10drg)')).toThrow(
'Rotate transform must be expressed in degrees (deg) or radians (rad): {"skewX":"10drg"}',
);
});

it('should throw when passing an Animated.Value', () => {
expect(() => processTransform([{rotate: {getValue: () => {}}}])).toThrow(
'You passed an Animated.Value to a normal component. You need to wrap that component in an Animated. For example, replace <View /> by <Animated.View />.',
);
});
});
});
Loading
Loading