Skip to content
Permalink
Browse files
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
  • Loading branch information
yungsters authored and facebook-github-bot committed Nov 3, 2019
1 parent 2504114 commit dcd63078bdab864830168005b940f638f1e08b23
Showing 4 changed files with 43 additions and 22 deletions.
@@ -10,6 +10,9 @@

'use strict';

import TestRenderer from 'react-test-renderer';
import * as React from 'react';

jest.mock('../../../BatchedBridge/NativeModules', () => ({
NativeAnimatedModule: {},
PlatformConstants: {
@@ -188,6 +191,24 @@ describe('Animated tests', () => {
expect(JSON.stringify(new Animated.Value(10))).toBe('10');
});

it('bypasses `setNativeProps` in test environments', () => {
const opacity = new Animated.Value(0);

const testRenderer = TestRenderer.create(
<Animated.View style={{opacity}} />,
);

expect(testRenderer.toJSON()).toMatchSnapshot();

Animated.timing(opacity, {
toValue: 1,
duration: 0,
useNativeDriver: false,
}).start();

expect(testRenderer.toJSON()).toMatchSnapshot();
});

it('warns if `useNativeDriver` is missing', () => {
jest.spyOn(console, 'warn').mockImplementationOnce(() => {});

@@ -0,0 +1,21 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Animated tests Animated bypasses \`setNativeProps\` in test environments 1`] = `
<View
style={
Object {
"opacity": 0,
}
}
/>
`;

exports[`Animated tests Animated bypasses \`setNativeProps\` in test environments 2`] = `
<View
style={
Object {
"opacity": 1,
}
}
/>
`;
@@ -42,8 +42,6 @@ function createAnimatedComponent<Props, Instance>(
_propsAnimated: AnimatedProps;
_eventDetachers: Array<Function> = [];

static __skipSetNativeProps_FOR_TESTS_ONLY = false;

constructor(props: Object) {
super(props);
}
@@ -106,7 +104,7 @@ function createAnimatedComponent<Props, Instance>(
// So a deferred call won't always be invoked.
this._invokeAnimatedPropsCallbackOnMount = true;
} else if (
AnimatedComponent.__skipSetNativeProps_FOR_TESTS_ONLY ||
process.env.NODE_ENV === 'test' ||
// For animating properties of non-leaf/non-native components
typeof this._component.setNativeProps !== 'function' ||
// In Fabric, force animations to go through forceUpdate and skip setNativeProps
@@ -125,25 +125,6 @@ jest
'../Libraries/Components/ActivityIndicator/ActivityIndicator',
),
)
.mock('../Libraries/Animated/src/Animated', () => {
const Animated = jest.requireActual('../Libraries/Animated/src/Animated');
Animated.Text.__skipSetNativeProps_FOR_TESTS_ONLY = true;
Animated.View.__skipSetNativeProps_FOR_TESTS_ONLY = true;
return Animated;
})
.mock('../Libraries/Animated/src/createAnimatedComponent', () => {
const createAnimatedComponent = jest.requireActual(
'../Libraries/Animated/src/createAnimatedComponent',
);

return Component => {
const Wrapped = createAnimatedComponent(Component);

Wrapped.__skipSetNativeProps_FOR_TESTS_ONLY = true;

return Wrapped;
};
})
.mock('../Libraries/AppState/AppState', () => ({
addEventListener: jest.fn(),
removeEventListener: jest.fn(),

0 comments on commit dcd6307

Please sign in to comment.