Skip to content

Errors thrown in event handlers are not propagating to tests #624

@armingjazi

Description

@armingjazi

Hey folks,

I'm not sure if this is an issue for this library, react or even jest-dom, so I'm starting here so where it leads:

for the following component

const ClickThrowsComponent = () => {
  const handleOnSectionClick = () => {
    throw new Error('some error')
  };
  return (
    <div data-testid='some-id'
      onClick={handleOnSectionClick}
    />
  );
};

the following test does not pass

test('should throw', () => {
  const { getByTestId } = render(<ClickThrowsComponent />);
  expect(()=>fireEvent.click(getByTestId('some-id'))).toThrow();
});

somehow the error is being swallowed on the way, I have tried almost all combinations with wrapping in act with async/awaits and promises to no avail

any help would be appreciated.

Reproduction repro

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