Skip to content

Commit dcd6307

Browse files
yungstersfacebook-github-bot
authored andcommitted
Animated: Delete __skipSetNativeProps_FOR_TESTS_ONLY
Summary: Deletes `__skipSetNativeProps_FOR_TESTS_ONLY` in favor of a `process.env_NODE_ENV` check (which will be eliminated from production builds). Changelog: [General] [Removed] Removed `__skipSetNativeProps_FOR_TESTS_ONLY` from Animated components. Reviewed By: TheSavior Differential Revision: D18289739 fbshipit-source-id: 7c1f7a29f2b88821d358227a07eec778773e418a
1 parent 2504114 commit dcd6307

File tree

4 files changed

+43
-22
lines changed

4 files changed

+43
-22
lines changed

Libraries/Animated/src/__tests__/Animated-test.js

+21
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
'use strict';
1212

13+
import TestRenderer from 'react-test-renderer';
14+
import * as React from 'react';
15+
1316
jest.mock('../../../BatchedBridge/NativeModules', () => ({
1417
NativeAnimatedModule: {},
1518
PlatformConstants: {
@@ -188,6 +191,24 @@ describe('Animated tests', () => {
188191
expect(JSON.stringify(new Animated.Value(10))).toBe('10');
189192
});
190193

194+
it('bypasses `setNativeProps` in test environments', () => {
195+
const opacity = new Animated.Value(0);
196+
197+
const testRenderer = TestRenderer.create(
198+
<Animated.View style={{opacity}} />,
199+
);
200+
201+
expect(testRenderer.toJSON()).toMatchSnapshot();
202+
203+
Animated.timing(opacity, {
204+
toValue: 1,
205+
duration: 0,
206+
useNativeDriver: false,
207+
}).start();
208+
209+
expect(testRenderer.toJSON()).toMatchSnapshot();
210+
});
211+
191212
it('warns if `useNativeDriver` is missing', () => {
192213
jest.spyOn(console, 'warn').mockImplementationOnce(() => {});
193214

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Animated tests Animated bypasses \`setNativeProps\` in test environments 1`] = `
4+
<View
5+
style={
6+
Object {
7+
"opacity": 0,
8+
}
9+
}
10+
/>
11+
`;
12+
13+
exports[`Animated tests Animated bypasses \`setNativeProps\` in test environments 2`] = `
14+
<View
15+
style={
16+
Object {
17+
"opacity": 1,
18+
}
19+
}
20+
/>
21+
`;

Libraries/Animated/src/createAnimatedComponent.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ function createAnimatedComponent<Props, Instance>(
4242
_propsAnimated: AnimatedProps;
4343
_eventDetachers: Array<Function> = [];
4444

45-
static __skipSetNativeProps_FOR_TESTS_ONLY = false;
46-
4745
constructor(props: Object) {
4846
super(props);
4947
}
@@ -106,7 +104,7 @@ function createAnimatedComponent<Props, Instance>(
106104
// So a deferred call won't always be invoked.
107105
this._invokeAnimatedPropsCallbackOnMount = true;
108106
} else if (
109-
AnimatedComponent.__skipSetNativeProps_FOR_TESTS_ONLY ||
107+
process.env.NODE_ENV === 'test' ||
110108
// For animating properties of non-leaf/non-native components
111109
typeof this._component.setNativeProps !== 'function' ||
112110
// In Fabric, force animations to go through forceUpdate and skip setNativeProps

jest/setup.js

-19
Original file line numberDiff line numberDiff line change
@@ -125,25 +125,6 @@ jest
125125
'../Libraries/Components/ActivityIndicator/ActivityIndicator',
126126
),
127127
)
128-
.mock('../Libraries/Animated/src/Animated', () => {
129-
const Animated = jest.requireActual('../Libraries/Animated/src/Animated');
130-
Animated.Text.__skipSetNativeProps_FOR_TESTS_ONLY = true;
131-
Animated.View.__skipSetNativeProps_FOR_TESTS_ONLY = true;
132-
return Animated;
133-
})
134-
.mock('../Libraries/Animated/src/createAnimatedComponent', () => {
135-
const createAnimatedComponent = jest.requireActual(
136-
'../Libraries/Animated/src/createAnimatedComponent',
137-
);
138-
139-
return Component => {
140-
const Wrapped = createAnimatedComponent(Component);
141-
142-
Wrapped.__skipSetNativeProps_FOR_TESTS_ONLY = true;
143-
144-
return Wrapped;
145-
};
146-
})
147128
.mock('../Libraries/AppState/AppState', () => ({
148129
addEventListener: jest.fn(),
149130
removeEventListener: jest.fn(),

0 commit comments

Comments
 (0)