This error occurred when the component with Select loaded before tests started. And I have no idea what happened and how to solve it.
I use CRA, RTL, and Typescript.
const CustomSelect = (props: SelectProps) => {
// ....
const getCaretIcon = ({ menuOpen }: IconState) => (
<StyledCaretIconSelect active={menuOpen}>
<CaretIcon className="select-caret-icon" />
</StyledCaretIconSelect>
);
const getCrossIcon = () => (
<>
<CrosstIcon className="select-cross-icon" />
<StyledSelectIconsDevider className="select-devider" />
</>
);
const handleOnChange = useCallback((option: OptionData) => onChange(option), []);
const getOptionValue = useCallback(
(option: OptionData): number | string =>
handleOptionValue(option),
[],
);
const getOptionLabel = useCallback(
(option: OptionData): number | string =>
handleOptionLabel(option),
[],
);
return (
<Select
initialValue={value}
options={options}
isInvalid={isInvalid}
isSearchable={isSearchable}
isClearable={isClearable}
isDisabled={isDisabled}
onOptionChange={handleOnChange}
getOptionValue={getOptionValue}
getOptionLabel={getOptionLabel}
caretIcon={getCaretIcon}
clearIcon={getCrossIcon}
themeConfig={ThemeSelectFilter}
required={required}
placeholder={placeholder}
hideSelectedOptions={false}
menuItemSize={selectMenuItemSize}
menuWidth={menuWidth}
/>
);
};
export default CustomSelect;
const ThemeSelectFilter: Partial<DefaultTheme> = {
color: {
border: 'transparent',
danger: `${COLORS.warning}`,
dangerLight: 'rgb(213 66 54 / 25%)',
disabled: `${COLORS.background.disabled}`,
placeholder: `${COLORS.text.light}`,
iconSeparator: 'transparent',
},
icon: {
padding: 0,
css: css`
svg {
fill: ${COLORS.text.light};
}
.select-caret-icon {
margin-bottom: 2px;
width: 12px;
height: 6px;
}
.select-cross-icon {
margin-right: 10px;
width: 10px;
height: 10px;
}
`,
},
control: {
minHeight: '20px',
borderWidth: '1px',
boxShadow: '0 0 0 0.18rem',
boxShadowColor: 'transparent',
focusedBorderColor: 'transparent',
padding: '0px 10px 0px 3px',
css: css`
font-weight: 600;
cursor: pointer;
`,
},
menu: {
padding: '8px',
borderRadius: `${SIZES.border.radius}`,
boxShadow: '0 2px 10px #00000029',
option: {
selectedColor: `${COLORS.text.main}`,
selectedBgColor: 'transparent',
padding: '5px 7px',
focusedBgColor: 'transparent',
},
},
noOptions: {
fontSize: `${SIZES.typography.body1}`,
margin: '0',
color: `${COLORS.text.light}`,
padding: '5px 7px',
},
};
But, I also got this error even without theming.