Skip to content

Allow testing of errors thrown after render #828

Closed
@lorensr

Description

@lorensr

Describe the feature you'd like:

I'd like to be able to write a passing test that verifies that when I fireEvent, an error is thrown. This test fails before it reaches the expect:

test('error is thrown', async () => {
  const { getByText } = render(<TodoApp />)
  await waitForDomChange();
  fireEvent.click(getByText('Add todo'));

  // test fails during this line
  await waitForDomChange(); 
  expect(1).toBeTruthy();
})

I'd like something to the effect of:

test('error is thrown', async () => {
  const { getByText } = render(<TodoApp />)
  await waitForDomChange();
  fireEvent.click(getByText('Add todo'));

  expect(await waitForDomChange()).toThrow();
})

Describe alternatives you've considered:

Adding an <ErrorBoundary> and testing both components together.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions