useAnimatedReaction Unit Test Failing #4941
Unanswered
Stewartarmbrecht
asked this question in
Q&A
Replies: 1 comment
-
As usual, take the time to write something out for help and you solve it immediately after. I was able to get the test to pass by adding a rerender call. Is that the right way to run this test? import { renderHook } from '@testing-library/react-native';
import { useSharedValue, useAnimatedReaction } from 'react-native-reanimated';
jest.useFakeTimers({ advanceTimers: true });
test('useAnimatedReaction', () => {
const callback = jest.fn();
const target = renderHook(() => {
const sharedValue = useSharedValue(0);
const reaction = useAnimatedReaction(
() => sharedValue.value,
(newValue, oldValue) => {
callback(newValue, oldValue);
},
[sharedValue.value],
);
return { sharedValue, reaction };
});
expect(callback).toHaveBeenCalledTimes(0);
target.result.current.sharedValue.value = 1;
jest.runAllTimers();
expect(callback).toHaveBeenCalledWith(1, null);
target.rerender({});
target.result.current.sharedValue.value = 2;
jest.runAllTimers();
expect(callback).toHaveBeenCalledWith(2, 1);
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Can anyone explain why this test fails?
With this error on the last line above:
Here is my jest jest.config.ts:
Here is my setupAfterEnv.ts file:
My jest.setup.ts is empty.
Here is my tsconfig.json file:
and Here is my package.json
Beta Was this translation helpful? Give feedback.
All reactions