Skip to content

Commit 6999082

Browse files
chore: Update AnimatedStyle and Animated tests
1 parent b45837a commit 6999082

File tree

5 files changed

+68
-532
lines changed

5 files changed

+68
-532
lines changed

Libraries/Animated/__tests__/Animated-test.js

Lines changed: 54 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,15 @@ describe('Animated tests', () => {
6262
);
6363

6464
expect(node.__getValue()).toEqual({
65-
style: [
66-
{
67-
backgroundColor: 'red',
68-
opacity: 0,
69-
transform: [{translate: [100, 100]}, {translateX: 100}, {scale: 0}],
70-
shadowOffset: {
71-
width: 0,
72-
height: 0,
73-
},
65+
style: {
66+
backgroundColor: 'red',
67+
opacity: 0,
68+
transform: [{translate: [100, 100]}, {translateX: 100}, {scale: 0}],
69+
shadowOffset: {
70+
width: 0,
71+
height: 0,
7472
},
75-
],
73+
},
7674
});
7775

7876
expect(anim.__getChildren().length).toBe(0);
@@ -86,21 +84,15 @@ describe('Animated tests', () => {
8684
expect(callback).toBeCalled();
8785

8886
expect(node.__getValue()).toEqual({
89-
style: [
90-
{
91-
backgroundColor: 'red',
92-
opacity: 0.5,
93-
transform: [
94-
{translate: [150, 150]},
95-
{translateX: 150},
96-
{scale: 0.5},
97-
],
98-
shadowOffset: {
99-
width: 0.5,
100-
height: 0.5,
101-
},
87+
style: {
88+
backgroundColor: 'red',
89+
opacity: 0.5,
90+
transform: [{translate: [150, 150]}, {translateX: 150}, {scale: 0.5}],
91+
shadowOffset: {
92+
width: 0.5,
93+
height: 0.5,
10294
},
103-
],
95+
},
10496
});
10597

10698
node.__detach();
@@ -181,15 +173,15 @@ describe('Animated tests', () => {
181173
<Animated.View style={{opacity}} />,
182174
);
183175

184-
expect(testRenderer.toJSON().props.style[0].opacity).toEqual(0);
176+
expect(testRenderer.toJSON().props.style.opacity).toEqual(0);
185177

186178
Animated.timing(opacity, {
187179
toValue: 1,
188180
duration: 0,
189181
useNativeDriver: false,
190182
}).start();
191183

192-
expect(testRenderer.toJSON().props.style[0].opacity).toEqual(1);
184+
expect(testRenderer.toJSON().props.style.opacity).toEqual(1);
193185
});
194186

195187
it('warns if `useNativeDriver` is missing', () => {
@@ -812,34 +804,30 @@ describe('Animated tests', () => {
812804
describe('Animated Vectors', () => {
813805
it('should animate vectors', () => {
814806
const vec = new Animated.ValueXY();
815-
const vecLayout = vec.getLayout();
816-
const opacity = vec.x.interpolate({
817-
inputRange: [0, 42],
818-
outputRange: [0.2, 0.8],
819-
});
820807

821808
const callback = jest.fn();
822809

823810
const node = new AnimatedProps(
824811
{
825812
style: {
826-
opacity,
813+
opacity: vec.x.interpolate({
814+
inputRange: [0, 42],
815+
outputRange: [0.2, 0.8],
816+
}),
827817
transform: vec.getTranslateTransform(),
828-
...vecLayout,
818+
...vec.getLayout(),
829819
},
830820
},
831821
callback,
832822
);
833823

834824
expect(node.__getValue()).toEqual({
835-
style: [
836-
{
837-
opacity: 0.2,
838-
transform: [{translateX: 0}, {translateY: 0}],
839-
left: 0,
840-
top: 0,
841-
},
842-
],
825+
style: {
826+
opacity: 0.2,
827+
transform: [{translateX: 0}, {translateY: 0}],
828+
left: 0,
829+
top: 0,
830+
},
843831
});
844832

845833
node.__attach();
@@ -851,14 +839,12 @@ describe('Animated tests', () => {
851839
expect(callback.mock.calls.length).toBe(2); // once each for x, y
852840

853841
expect(node.__getValue()).toEqual({
854-
style: [
855-
{
856-
opacity: 0.8,
857-
transform: [{translateX: 42}, {translateY: 1492}],
858-
left: 42,
859-
top: 1492,
860-
},
861-
],
842+
style: {
843+
opacity: 0.8,
844+
transform: [{translateX: 42}, {translateY: 1492}],
845+
left: 42,
846+
top: 1492,
847+
},
862848
});
863849

864850
node.__detach();
@@ -951,15 +937,13 @@ describe('Animated tests', () => {
951937
expect(listener.mock.calls.length).toBe(2);
952938
expect(listener).toBeCalledWith({value: 137});
953939
expect(view.__getValue()).toEqual({
954-
style: [
955-
{
956-
transform: [
957-
{
958-
translateX: 137,
959-
},
960-
],
961-
},
962-
],
940+
style: {
941+
transform: [
942+
{
943+
translateX: 137,
944+
},
945+
],
946+
},
963947
});
964948
value4.removeListener(id);
965949
value1.setValue(40);
@@ -1027,18 +1011,17 @@ describe('Animated tests', () => {
10271011

10281012
it('should animate colors', () => {
10291013
const color = new Animated.Color({r: 255, g: 0, b: 0, a: 1.0});
1030-
const scale = color.a.interpolate({
1031-
inputRange: [0, 1],
1032-
outputRange: [1, 2],
1033-
});
10341014
const callback = jest.fn();
10351015
const node = new AnimatedProps(
10361016
{
10371017
style: {
10381018
backgroundColor: color,
10391019
transform: [
10401020
{
1041-
scale,
1021+
scale: color.a.interpolate({
1022+
inputRange: [0, 1],
1023+
outputRange: [1, 2],
1024+
}),
10421025
},
10431026
],
10441027
},
@@ -1047,12 +1030,10 @@ describe('Animated tests', () => {
10471030
);
10481031

10491032
expect(node.__getValue()).toEqual({
1050-
style: [
1051-
{
1052-
backgroundColor: 'rgba(255, 0, 0, 1)',
1053-
transform: [{scale: 2}],
1054-
},
1055-
],
1033+
style: {
1034+
backgroundColor: 'rgba(255, 0, 0, 1)',
1035+
transform: [{scale: 2}],
1036+
},
10561037
});
10571038

10581039
node.__attach();
@@ -1061,12 +1042,10 @@ describe('Animated tests', () => {
10611042
color.setValue({r: 11, g: 22, b: 33, a: 0.5});
10621043
expect(callback.mock.calls.length).toBe(4);
10631044
expect(node.__getValue()).toEqual({
1064-
style: [
1065-
{
1066-
backgroundColor: 'rgba(11, 22, 33, 0.5)',
1067-
transform: [{scale: 1.5}],
1068-
},
1069-
],
1045+
style: {
1046+
backgroundColor: 'rgba(11, 22, 33, 0.5)',
1047+
transform: [{scale: 1.5}],
1048+
},
10701049
});
10711050

10721051
node.__detach();

0 commit comments

Comments
 (0)