开玩笑:TypeError:无法读取未定义的属性(Reading' getFilename')

发布于 2025-02-12 10:03:07 字数 1272 浏览 0 评论 0原文

我最近开始使用 @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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2025-02-19 10:03:07

尝试使用行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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文