Skip to content

TypeError: convert is not a function in testing-library render #225

@elramus

Description

@elramus

Describe the bug

When rendering the SVG component in a render function from testing-library/react, the SVG does not render and its onError function fires, saying:

TypeError: convert is not a function
    at getNode (file:///Users/dramus/Sites/svg-test/node_modules/react-inlinesvg/src/modules/utils.ts:28:18)

Your minimal, reproducible example

Can't make sandbox cause it happens when running tests via command line

Steps to reproduce

Not quite sure how to put this into a sandbox since it happens when running a test via command line, but you can reproduce by creating a new, clean Vite React TS project, adding vitest and react testing library, and making a simple test to try and render it.

import SVG from 'react-inlinesvg'

import { render, screen } from '@testing-library/react'

describe('Svg', async () => {
  it('renders in a test', async () => {
    render(
      <SVG
        src="<svg>test</svg>"
        onError={(e) => {
          console.log(e)
        }}
      />
    )

    await screen.findByText('test')
  })
})

Expected behavior

Render the SVG the same as it does when not testing

How often does this bug happen?

Every time

Screenshots or Videos

Screenshot 2023-12-14 at 10 52 18 AM

Platform

Mac OS, Sanoma 14.2, M2 chip

react-inlinesvg version

4.1.0

TypeScript version

5.2.2

Build tool

Vite

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions