【问题标题】:screen.debug() in the @testing-library/react gives "Unexpected debug statement"@testing-library/react 中的 screen.debug() 给出了“意外的调试语句”
【发布时间】:2023-01-30 18:07:26
【问题描述】:

我试图使用 debug() 但它在控制台中给出错误: “意外的调试语句”这里有什么问题?

import { render, screen } from '@testing-library/react';
import { userEvent } from '@testing-library/user-event';
import Home from './Home';
import App from './App';


test("Home input test",  () => {
  render(<Home />)
  const Field = screen.getByLabelText(/HOME/i);
  userEvent.type(Field, 'User'); 
  screen.debug();
});

【问题讨论】:

  • 你能显示完整的错误堆栈吗?

标签: reactjs unit-testing testing react-testing-library


【解决方案1】:

这不是错误。这只是一个 ESlint 警告。它会警告您,您有一些代码会在您运行测试时在控制台上打印出一些内容。

您可以禁用它。 from here

您可以控制检查哪些调试实用程序 utilsToCheckFor 选项:

{
  "testing-library/no-debugging-utils": [
      "error",
      {
          "utilsToCheckFor": {
              "debug": false,
              "logRoles": true,
              "logDOM": true
          }
      }
  ]
}

【讨论】:

    猜你喜欢
    • 2020-05-12
    • 1970-01-01
    • 2020-05-02
    • 1970-01-01
    • 2021-03-02
    • 2019-05-21
    • 2019-11-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多