首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么在@testing library/user-event上不存在clear方法

为什么在@testing library/user-event上不存在clear方法
EN

Stack Overflow用户
提问于 2020-06-08 16:46:09
回答 1查看 1.9K关注 0票数 3

我正在做一个CMS项目,我刚刚遇到了一个问题。_userEvent.default.clear is not a function

代码语言:javascript
复制
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时,我看到了这些行

代码语言:javascript
复制
// 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;

如文件所示,userEvent上没有clear()方法。但是文档指出了clear()方法。

文档=> Doc

这是我第一次使用这个库。有人知道问题出在哪里吗?

EN

回答 1

Stack Overflow用户

发布于 2021-09-08 02:57:08

您必须将@ latest library/user-event更新为最新版本。那么这个错误就会被解决。你可以在这里找到最新的版本:https://www.npmjs.com/package/@testing-library/user-event

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62258250

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档