当我运行 Jest 测试时,是否可以选择显示所有测试描述? [英] Is there an option to show all test descriptions when I run jest tests?
问题描述
我在我的 create-react-app 项目中使用了 jest 和酶.当我运行 npm test
时,我得到一个输出,显示通过的测试文件的名称,但我希望输出还包括测试的名称.
I'm using jest and enzyme with my create-react-app project. When I run npm test
, I get an output that shows the names of the test files that passed but I'd like the output to also include the names of the tests.
示例:
Button.test.js
Button.test.js
it ('renders button', () => {
const button = shallow(<Button type="save"/>);
expect(toJson(button)).toMatchSnapshot();
});
现在当我运行 npm test 时,输出只是:
Right now when I run npm test the output is just:
通过 src/Button.test.js"
PASS src/Button.test.js"
以及通过和失败测试的数量(当测试成功时).我希望输出包含渲染按钮"和任何其他测试描述(例如运行 rspec 测试时输出的外观).
and the number of passed and failed tests (when the tests are successful). I would like the output to include "renders button" and any other test descriptions (like how the output looks when an rspec test is run).
推荐答案
--详细
使用测试套件层次结构显示单个测试结果.
Display individual test results with the test suite hierarchy.
这么跑
jest --verbose
将打印 describe
、it
、test
块中的所有名称.
如果你用 yarn
运行测试,你可以做
Will print all the names in describe
, it
, test
blocks.
If you're running tests with yarn
, you can do
yarn test --verbose
如果你使用 npm
运行测试,你可以这样做
If you're running tests with npm
, you can do
npm test -- --verbose
如果要设为默认值,请更改 package.json
If you want to make this default, change your test script in package.json
"test": "react-scripts test --env=jsdom --verbose",
现在 yarn test
和 npm test
都应该显示所有测试名称.
Now both yarn test
and npm test
should show all test names.
这篇关于当我运行 Jest 测试时,是否可以选择显示所有测试描述?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!