我在我的 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
将打印 describe
、it
、test
block 中的所有名称。
如果您使用 yarn
运行测试,您可以这样做
yarn test --verbose
如果您使用 npm
运行测试,则可以这样做
npm test -- --verbose
如果您想将此设置为默认值,请更改 package.json
中的测试脚本
"test": "react-scripts test --env=jsdom --verbose",
现在 yarn test
和 npm test
都应该显示所有测试名称。
关于reactjs - 当我运行 Jest 测试时,是否有一个选项可以显示所有测试描述?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50497630/