lookfirst / mui-rff

MUI 5 / Material UI + React Final Form
https://lookfirst.github.io/mui-rff/
MIT License
488 stars 93 forks source link

Test errors with Autocomplete #1171

Closed d3spis3d closed 1 week ago

d3spis3d commented 2 weeks ago

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.