forked from software-mansion/react-native-reanimated
/
hooks.useSharedValue.test.js
32 lines (25 loc) · 999 Bytes
/
hooks.useSharedValue.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import React from 'react';
import renderer from 'react-test-renderer';
import Animated, { useSharedValue } from '../src';
jest.mock('../src/ReanimatedEventEmitter');
jest.mock('../src/ReanimatedModule');
jest.mock('../src/reanimated2/NativeReanimated/NativeReanimated');
describe('useSharedValue', () => {
it('retains value on rerender', () => {
// Given
const initialValue = 0;
const updatedValue = 1;
function TestComponent(props) {
const opacity = useSharedValue(props.value);
return <Animated.View style={{ opacity: opacity.value }} />;
}
// When rendering with initial value
const wrapper = renderer.create(
<TestComponent key="box" value={initialValue} />
);
expect(wrapper.root.children[0].props.style.opacity).toBe(initialValue);
// When rendering with updated value
wrapper.update(<TestComponent key="box" value={updatedValue} />);
expect(wrapper.root.children[0].props.style.opacity).toBe(initialValue);
});
});