【问题标题】:Is there an option to show all test descriptions when I run jest tests?当我运行玩笑测试时,是否有显示所有测试描述的选项?
【发布时间】:2018-11-02 23:45:21
【问题描述】:

我在我的 create-react-app 项目中使用 jest 和酵素。当我运行npm test 时,我得到一个输出,其中显示了通过的测试文件的名称,但我希望输出也包括测试的名称。

例子:

Button.test.js

it ('renders button', () => {
    const button = shallow(<Button type="save"/>);
    expect(toJson(button)).toMatchSnapshot();
});

现在当我运行 npm test 时,输出只是:

通过 src/Button.test.js"

以及通过和失败的测试次数(测试成功时)。我希望输出包含“渲染按钮”和任何其他测试描述(例如运行 rspec 测试时输出的外观)。

【问题讨论】:

    标签: reactjs jestjs enzyme create-react-app


    【解决方案1】:

    来自Jest's command-line options docs

    --详细

    使用测试套件层次结构显示单个测试结果。

    这样跑

    jest --verbose
    

    将打印describeittest 块中的所有名称。
    如果您使用yarn 运行测试,您可以这样做

    yarn test --verbose
    

    如果您使用 npm 运行测试,您可以这样做

    npm test -- --verbose
    

    如果您想将此设为默认值,请在 package.json 中更改您的测试脚本

    "test": "react-scripts test --env=jsdom --verbose",
    

    现在yarn testnpm test 都应该显示所有测试名称。

    【讨论】:

      【解决方案2】:

      注意,不是

      jest --verbose
      

      您也可以在jest.config.jsverbose设置为true

      // jest.config.js
      module.exports = {
        ...
        verbose: true,
      }
      

      【讨论】:

      • 添加到jest.config.js 是使用vue cli 4并运行npm run test:unit时的唯一方法
      【解决方案3】:

      --verbose 标志听起来可能会满足您的需求。根据docs,显示个别测试结果。

      【讨论】:

      • 我尝试使用它,但输出似乎没有任何不同
      • 你的 npm 脚本和 jest 配置的内容是什么?
      • @Sendai 记得添加两个连字符以从 npm 参数转义到 jest 参数 - 像这样:npm test -- --verbose。 (否则,--verbose 参数转到npm,您看到的是详细的npm 输出,而不是详细的jest 输出。)
      【解决方案4】:

      我在使用 create-react-app(同时使用 jest 和酶)时遇到了同样的问题,但是在 package.json 中使用 --verbose=true 附加现有的 test 脚本后,我能够让测试出现。所以现在出现"test": "react-scripts test --env=jsdom --verbose=true"

      【讨论】:

        【解决方案5】:

        在 package.json("test": "react-scripts test --env=jsdom --verbose",) 中进行此配置后,尝试通过 npm test 运行您的测试。

        注意:使用 npm 运行测试描述也没有反映给我。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2019-04-18
          • 2017-05-10
          • 2019-01-18
          • 2021-03-19
          • 1970-01-01
          • 2018-05-04
          • 1970-01-01
          • 2015-06-08
          相关资源
          最近更新 更多