我正在做一个 CMS 项目,但我遇到了一个问题。_userEvent.default.clear is not a function
.
import user from '@testing-library/user-event'
test('can edit label', async () => {
createArticleMock()
await renderRootAndInitStore(rightNowTeasers, globalInitialState)
const index = 1
const input = screen.getByDisplayValue(labels[index])
const newLabel = 'VÄRLDEN'
user.clear(input)
user.type(input, newLabel)
expect(await screen.findByDisplayValue(newLabel))
user.click(screen.getByTestId('settings-form-save'))
await screen.findByText(newLabel)
})
当我访问时@testing-library/user-event
,我看到了那些线条
// Definitions by: Wu Haotian <https://github.com/whtsky>
export interface IUserOptions {
allAtOnce?: boolean;
delay?: number;
}
export interface ITabUserOptions {
shift?: boolean;
focusTrap?: Document | Element;
}
export type TargetElement = Element | Window;
declare const userEvent: {
click: (element: TargetElement) => void;
dblClick: (element: TargetElement) => void;
selectOptions: (element: TargetElement, values: string | string[]) => void;
type: (
element: TargetElement,
text: string,
userOpts?: IUserOptions
) => Promise<void>;
tab: (userOpts?: ITabUserOptions) => void;
};
export default userEvent;
如文件所示,clear()
在userEvent
. 但是文档指出了clear()
方法。
文档 =>文档
这是我第一次使用这个库。任何人都知道问题是什么?