mantine icon indicating copy to clipboard operation
mantine copied to clipboard

Select component compatibility with React testing library data-testid and fireEvent

Open oiqwrwer1 opened this issue 2 years ago • 2 comments

What package has an issue

@mantine/core

Describe the bug

I'm using the Select mantine/core component and trying to write unit tests for the parent component that uses Select where onTimeZoneChange below is a prop passed to the parent component.

return ( <Select data-testid={testIdTimeZonePickerSelect} className={classes.select} label={tokenStrings.TimeZone.Label} data={dataList} value={timeZone} onChange={onTimeZoneChange} searchable placeholder={tokenStrings.TimeZone.Prompt} withAsterisk ></Select> );

To that end, I tried tagging the Select component with a data-testid and writing a react testing library test to verify the onChange behavior. fireEvent.change(screen.getByTestId(testIdTimeZonePickerSelect), { target: { value: targetTimeZone }, });

The onChange function does not get called.

What version of @mantine/hooks page do you have in package.json?

5.9.4

If possible, please include a link to a codesandbox with the reproduced problem

No response

Do you know how to fix the issue

No

Are you willing to participate in fixing this issue and create a pull request with the fix

None

Possible fix

No response

oiqwrwer1 avatar Jan 25 '23 21:01 oiqwrwer1

Is there a plan to fix this?

oiqwrwer1 avatar Mar 07 '23 19:03 oiqwrwer1

Yes, it is in the backlog, but there won't be any guides soon.

rtivital avatar Mar 07 '23 20:03 rtivital

A guide for testing Select and other combobox components has been added to the help center – https://help.mantine.dev/q/combobox-testing

rtivital avatar Mar 15 '24 13:03 rtivital