Skip to content

fireEvent cannot be triggered on elements with pointer events box only #1387

Closed
@pierrezimmermannbam

Description

@pierrezimmermannbam

Describe the bug

The following test will fail

test('works on pressable with pointer event to box-only', () => {
  const mockOnPress = jest.fn();

  const screen = render(
    <Pressable
      onPress={mockOnPress}
      pointerEvents="box-only"
      testID="pressable"
    />
  );

  fireEvent.press(screen.getByTestId('pressable'));
  expect(mockOnPress).toHaveBeenCalled();
});

What happens is that the pointer-events condition checks that there is not box-only on the parent but here the parent is the composite element and it has box-only so the element is considered to be disabled.

Expected behavior

The test should pass

Steps to Reproduce

Versions

I've written the test in the up to date repo of RNTL

I think this can be fixed if we look at the host parent instead of the direct parent using the method getHostParent. I'll try to submit a PR soon for this. I have made a version of the function that checks pointer-events in #1386 which could be used by fireEvent I think

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions