5

我正在做一个 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()方法。

文档 =>文档

这是我第一次使用这个库。任何人都知道问题是什么?

4

1 回答 1

2

您必须将 @testing-library/user-event 更新到最新版本。然后该错误将得到解决。您可以在这里找到最新版本: https ://www.npmjs.com/package/@testing-library/user-event

于 2021-09-08T02:57:08.463 回答