reactjs - 当我运行 Jest 测试时,是否有一个选项可以显示所有测试描述?

标签 reactjs jestjs enzyme create-react-app

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

示例:

按钮.test.js

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

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

PASS src/Button.test.js"

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

最佳答案

来自Jest's command-line options docs

--verbose

Display individual test results with the test suite hierarchy.

所以运行

jest --verbose

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

yarn test --verbose

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

npm test -- --verbose

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

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

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

关于reactjs - 当我运行 Jest 测试时,是否有一个选项可以显示所有测试描述?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50497630/

相关文章:

javascript - 上下文 API,如何不使用类?

reactjs - 如何使用 jest/enzyme 中的 "current"属性测试 useRef

reactjs - 使用jestjs进行单元测试时如何获取组件的props

unit-testing - 我应该从 JEST 跟踪 'snapshots' 吗?

reactjs - 如何正确构建使用 React 的全栈项目?

reactjs - 如何使用 Reactstrap 检查复选框的选中值

javascript - Reactjs:组件的 Jsx 三元内联(嵌套三元)

node.js - 用 Jest 测试 GraphQL 解析器

javascript - 如何使用 Jest/Enzyme 在功能性 React 组件中测试 lambda 函数?

javascript - 在 Jest 中进行单元测试时模拟 vscode API