software-mansion / react-native-gesture-handler

Declarative API exposing platform native touch and gesture system to React Native.
https://docs.swmansion.com/react-native-gesture-handler/
MIT License
5.83k stars 952 forks source link

Add `jest.useFakeTimers()` in jestSetup.js #2818

Open heecheolman opened 1 month ago

heecheolman commented 1 month ago

Description

✅ Success Case

❌ Fail Case

👉 So, I added jest.useFakeTimers() in jestSetup.js

Test plan

  1. Setup project, without "react-native-reanimated" package.
  2. Setup Jest
  3. Write this simple test code.
import { GestureDetector, Gesture } from 'react-native-gesture-handler';
import { Text } from 'react-native';
import { render, screen } from '@testing-library/react-native';

describe('Test', () => {
  it('Success', () => {
      function TestComponent() {
        const gesture = Gesture.Pan().onEnd(() => {});

        return (
          <GestureDetector gesture={gesture}>
              <Text>DummyText</Text>
          </GestureDetector>
      }

      render(<TestComponent />);
      expect(screen.getByText('DummyText')).toBeOnTheScreen();
  });
})
j-piasecki commented 1 month ago

Can you share more details about the setup where your tests were failing? Like the versions of:

Or preferably, can you set up a repository with a project where the test is failing because of Gesture Handler?