admin管理员组文章数量:1297016
I am working on a CMS project and I just came across an issue. _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)
})
When I visit @testing-library/user-event
, I see those lines
// Definitions by: Wu Haotian <;
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;
As the file shows, there is no clear()
method on userEvent
. But the documentation points out to clear()
method.
Doc => Doc
This is first time I use this library. Anyone knows what the issue is?
I am working on a CMS project and I just came across an issue. _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)
})
When I visit @testing-library/user-event
, I see those lines
// Definitions by: Wu Haotian <https://github./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;
As the file shows, there is no clear()
method on userEvent
. But the documentation points out to clear()
method.
Doc => Doc
This is first time I use this library. Anyone knows what the issue is?
Share edited Jul 20, 2021 at 9:10 Nicky McCurdy 19.6k5 gold badges60 silver badges88 bronze badges asked Jun 8, 2020 at 8:46 cooskuncooskun 6783 gold badges8 silver badges22 bronze badges 2-
1
It looks like those types are missing two of the documented methods -
toggleSelectOptions
isn't there either. They're both there in the latest version (github./testing-library/user-event/blob/master/typings/…), maybe you need to update or wait for a release. – jonrsharpe Commented Jun 8, 2020 at 8:50 -
npm i -D @testing-library/user-event
andnpm audit fix
solved the issue. Thanks jonrsharpe – cooskun Commented Jun 8, 2020 at 9:22
2 Answers
Reset to default 5You Have to update the @testing-library/user-event to the latest version. Then that error will be resolved. You Can find the latest version over here: https://www.npmjs./package/@testing-library/user-event
As discussed in the other answers/ments, the best solution is to upgrade @testing-library/user-event
. However, if you are stuck on an old version for some reason, you can use this workaround.
Instead of this:
user.clear(input);
try this:
user.type(input, "", { allAtOnce: true });
本文标签: javascriptWhy clear method not exist on testinglibraryusereventStack Overflow
版权声明:本文标题:javascript - Why clear method not exist on @testing-libraryuser-event - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741647043a2390246.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论