Skip to content

Not able to test an Imgix image with Jest #923

Description

@reemobeid17

Describe the bug
I'm trying to write a Jest unit test for one of my components that is rendering an Imgix image. The test is breaking with this error TypeError: Cannot read properties of undefined (reading 'split')

To Reproduce
Run a test that renders an Imgix component render(<Imgix src="https://www.google.com/image-url" htmlAttributes={{ alt: "Image alt" }} />) using @testing-library/react

and then test

  await waitFor(() => {
      const imgElement = getByAltText("Image alt");
      expect(imgElement).toBeInTheDocument();
  });

Expected behaviour
Expect the test to succeed and image tag to be part of the document when testing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions