Skip to content

Commit

Permalink
Animated: Delete __skipSetNativeProps_FOR_TESTS_ONLY
Browse files Browse the repository at this point in the history
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 dcd6307
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 22 deletions.
21 changes: 21 additions & 0 deletions Libraries/Animated/src/__tests__/Animated-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

'use strict';

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

jest.mock('../../../BatchedBridge/NativeModules', () => ({
NativeAnimatedModule: {},
PlatformConstants: {
Expand Down Expand Up @@ -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(() => {});

Expand Down
Original file line number Diff line number Diff line change
@@ -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,
}
}
/>
`;
4 changes: 1 addition & 3 deletions Libraries/Animated/src/createAnimatedComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ function createAnimatedComponent<Props, Instance>(
_propsAnimated: AnimatedProps;
_eventDetachers: Array<Function> = [];

static __skipSetNativeProps_FOR_TESTS_ONLY = false;

constructor(props: Object) {
super(props);
}
Expand Down Expand Up @@ -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
Expand Down
19 changes: 0 additions & 19 deletions jest/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit dcd6307

Please sign in to comment.