将 @testing-library/user-event 更新到 v.14 时出错
我正在遵循最新版本的所有说明@testing-library/user-event
。
之前:
test('request support action',() => {
render(<SupportSection requestSupport={requestSupport} />);
const button = screen.getByRole('button');
userEvent.click(button);
expect(requestSupport).toHaveBeenCalled();
});
之后:
test('request support action', async () => {
const user = userEvent.setup();
render(<SupportSection requestSupport={requestSupport} />);
const button = screen.getByRole('button');
await user.click(button);
expect(requestSupport).toHaveBeenCalled();
});
requestSupport
在更高的范围const requestSupport = jest.fn();
我遇到的错误是:
typeerror:range.clonerange不是函数
我的所有测试都在库更新之前通过,现在都失败了。
I was following all the instructions for the newest version of @testing-library/user-event
.
BEFORE:
test('request support action',() => {
render(<SupportSection requestSupport={requestSupport} />);
const button = screen.getByRole('button');
userEvent.click(button);
expect(requestSupport).toHaveBeenCalled();
});
AFTER:
test('request support action', async () => {
const user = userEvent.setup();
render(<SupportSection requestSupport={requestSupport} />);
const button = screen.getByRole('button');
await user.click(button);
expect(requestSupport).toHaveBeenCalled();
});
requestSupport
is mocked in the higher scope const requestSupport = jest.fn();
The error I'm getting is:
TypeError: range.cloneRange is not a function
All my tests were passing before the library updates, now all failing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我终于找到了解决方案,由于一些旧模拟而发生了错误,这是先前的测试环境。所有必须完成的工作是从jest配置文件中删除下面的下面:
I finally found the solution, the error occured due to some old mock, that previous test environment required. All that must be done, was to remove below from jest config file: