Skip to content

Test errors with Autocomplete #1171

Closed
Closed

Description

@d3spis3d

Describe the bug
When testing a component that uses the <Autocomplete /> component from mui-rff I encounter an error:

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.

    Check the render method of `AutocompleteWrapper`.

at input (/Users/code/mui-rff-autocomplete-test/node_modules/mui-rff/src/Autocomplete.tsx:76:3)
        at Field (/Users/code/mui-rff-autocomplete-test/node_modules/react-final-form/dist/react-final-form.cjs.js:718:26)
        at name (/Users/code/mui-rff-autocomplete-test/node_modules/mui-rff/src/Autocomplete.tsx:44:10)
        at form
        at ReactFinalForm (/Users/code/mui-rff-autocomplete-test/node_modules/react-final-form/dist/react-final-form.cjs.js:178:20)

My test minimal reproduction test case looks like:

import { render } from "@testing-library/react"
import {Autocomplete} from "mui-rff"
import { Form } from "react-final-form"


test("renders autocomplete", () => {
    const options = [
        {value: "1", label: "one"},
        {value: "2", label: "two"},
    ]

    const rendered = render(
        <Form
            onSubmit={() => {
            }}
            render={({handleSubmit}) => (
                <form onSubmit={handleSubmit}>
                    <Autocomplete name="test" label="test" options={options}/>
                </form>
            )}
        />,
    )
})

Any ideas or suggestions on what's causing the error in my tests would be much appreciated. I checked the tests in this repo to compare against my own, but with no luck.

To Reproduce
I've tried to create a minimal reproduction of the issue in https://github.com/d3spis3d/mui-rff-autocomplete-test

  1. Clone the repo
  2. Run yarn && yarn test

Expected behavior
<Autocomplete /> renders in the test without errors.

Activity

  1. Repository owner locked and limited conversation to collaborators on Sep 27, 2024
  2. converted this issue into a discussion #1175 on Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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