开玩笑:TypeError:无法读取未定义的属性(Reading' getFilename')
我最近开始使用 @testing-library/user-event库,并且面临很多问题。我正在尝试测试文本框验证流量,但是我遇到了错误,
TypeError: Cannot read properties of undefined (reading 'getFileName')
at _default (node_modules/@jest/source-map/build/getCallsite.js:86:60)
at Function.write (node_modules/@jest/console/build/BufferedConsole.js:104:51)
at console._logError (node_modules/@jest/console/build/CustomConsole.js:107:12)
at console.error (node_modules/@jest/console/build/CustomConsole.js:147:10)
这是我的测试柜
test('allows user to add comments in the comment Box', () => {
render(
<ApproveModal
showApproveModal={showApproveModal}
updateApproveModal={updateApproveModal}
requestId={requestId}
hierarchyId={hierarchyId}
/>
);
expect(screen.getByText('Enter few details before Approval')).toBeInTheDocument();
const commentTextBox = screen.getByRole('textbox');
userEvent.type(commentTextBox, 'Approved By Admin');
expect(screen.queryByText('Please input a Valid Comment!')).not.toBeInTheDocument();
userEvent.type(commentTextBox, '');
// expect(screen.queryByText('Please input a Valid Comment!')).toBeInTheDocument();
});
以前是否有人遇到了这个问题?
I recently started using the @testing-library/user-event library and I am facing a lot of issues. I am trying to test a textbox validation flow however I am getting the error
TypeError: Cannot read properties of undefined (reading 'getFileName')
at _default (node_modules/@jest/source-map/build/getCallsite.js:86:60)
at Function.write (node_modules/@jest/console/build/BufferedConsole.js:104:51)
at console._logError (node_modules/@jest/console/build/CustomConsole.js:107:12)
at console.error (node_modules/@jest/console/build/CustomConsole.js:147:10)
This is my testcase
test('allows user to add comments in the comment Box', () => {
render(
<ApproveModal
showApproveModal={showApproveModal}
updateApproveModal={updateApproveModal}
requestId={requestId}
hierarchyId={hierarchyId}
/>
);
expect(screen.getByText('Enter few details before Approval')).toBeInTheDocument();
const commentTextBox = screen.getByRole('textbox');
userEvent.type(commentTextBox, 'Approved By Admin');
expect(screen.queryByText('Please input a Valid Comment!')).not.toBeInTheDocument();
userEvent.type(commentTextBox, '');
// expect(screen.queryByText('Please input a Valid Comment!')).toBeInTheDocument();
});
Has anybody faced this issue before?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用行
const user = userevent.setup()
实例化USEREVENT类,然后用用户替换现有的USEREVENT呼叫。这也可能对您有所帮助: https://testesting-library.com/docs/docs/docs/user - 事件/设置
另外,最好一次渲染一个组件,而不是多个组件,然后尝试测试您在该特定上测试的内容 成分。
Try to instantiate the userEvent class with the line
const user = userEvent.setup()
and replace the existing userEvent calls with user.This might help you as well: https://testing-library.com/docs/user-event/setup
Also, it may be better to render only one component at a time instead of multiple and then try to test what you are testing on that specific component.