我的项目基于Create-react-app设置,我用于测试单元测试的package.json脚本如下
"scripts": {
"test": "react-scripts test --coverage",
}
或
"test": "react-scripts test --coverage --collectCoverageFrom=src/**/*.{js,jsx}
它在 Test 文件夹中执行测试,但不显示覆盖率报告。您能帮助解决此问题吗?
我的文件结构如下 src | --- 测试 --- components> moduleA> package1> package2> transaction.js,abcd.js ...等
ProcessEvent.test.js
describe('ProcessEvent Component', () => {
const expectedProps = {
"event": {iconStatus:'active', desc:'abc'}
}
it('should render without error', () => {
const component = <ProcessEvent {...expectedProps}/>
const wrapper = component.find('.eventclass');
expect(wrapper.length).toBe(1);
});
it('should receive valid props', () => {
const component = shallow(<ProcessEvent {...expectedProps}/>);
const wrapper = component.find('.eventclass');
expect(component.props).toBeDefined();
});
});
答案 0 :(得分:0)
使用--watchAll=false
参数可以列出所有文件。
示例package.json
{
...
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test",
"coverage": "react-app-rewired test -- --coverage --watchAll=false",
"eject": "react-scripts eject",
"serve": "node server.js"
},
...
}
您的承保范围报告也位于/ coverage / lcov-report。打开此处的index.html,将在浏览器中显示覆盖率报告。