react-native-gesture-handler: Unable to find node on an unmounted component error

=== Open the issue

Description

Screenshots

image

Steps To Reproduce

  1. Install the libraries listed below
  2. Follow the jest expo guideline
  3. Create two files below
  4. Run jest

Expected behavior

To render TouchableOpacity. TouchableOpacity from react-native renders just fine.

Actual behavior

Throws error provided in Screenshots section.

Minimal code example

Test file:

import React from 'react';
import { cleanup, render } from '@testing-library/react-native';
import { Gesture } from '../Gesture';

describe('HeaderRightButton filter', () => {
  afterEach(() => {
    jest.clearAllMocks();
    cleanup();
  });

  it('should render', () => {
    const { getByTestId } = render(<Gesture/>);
  });
});

Component file:

import React, { FC } from 'react';
import { View, Text } from 'react-native';
import { TouchableOpacity } from 'react-native-gesture-handler';

export const Gesture: FC = () => {
  return (
    <View>
      <TouchableOpacity
        onPress={() => console.log('@1')}
      >
        <Text>asdf</Text>
      </TouchableOpacity>
    </View>
  );
};

Package versions

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 9
  • Comments: 15 (3 by maintainers)

Commits related to this issue

Most upvoted comments

I was facing the same issue, so I’ve updated react-test-renderer to version 17.0.2 and worked.

Any update on it @jakub-gonet , @iaurg ? I’m experiencing the exact same problem. Upgrading react-test-renderer to version 17.0.2 didn’t worked. 😕

My package version:

React: 17.0.2
React Native: "react-native": "https://github.com/expo/react-native/archive/sdk-41.0.0.tar.gz",
React Native Gesture Handler: 1.10.3
Ubuntu 20
expo 41.0.1
jest-expo: 42.0.0
@testing-library/react-native: "7.2.0"
react-test-renderer: 17.0.2

Any update on this? Are there specific rngh mocks that are missing that need to be added?

I solved this issue by solving the warning using act

import { act } from 'react-test-renderer';

describe('When rendering xxx', () => {
  describe('With a random state', () => {
    beforeAll(() => {
      act(() => {
        store.dispatch(xxx.update(xxxMock));
        store.dispatch(yyy.update(yyyMock));
      });
    });
    it('should render it correctly', () => {
      expectToMatchSnapshot({ component: <xxx />, store });
    });
  });
});

We have the exact same behavior.

Yes Im having this same error, in my case im using Gesture.LongPress() and is throwing me TypeError: Cannot read properties of undefined (reading 'LongPress') 😢

Are you using the mocks, as documented here: https://docs.swmansion.com/react-native-gesture-handler/docs/guides/testing ?

This did not solve the problem for me.

@iaurg That worked for us, thanks!!

This problem is caused by missing rngh mocks. You can mock rngh components by yourself as a workaround.