我只是将我的项目从react 0.53.3升级到0.57.3。升级后,我的笑话测试不再通过,因为不再达到我的覆盖范围阈值。就我而言,这绝对是配置错误,但是我无法弄清楚为了解决该问题必须进行哪些调整。对于此问题,我提出了最简单的文件来解决。问题发生在我的整个项目中,但是我无法真正分享整个事情。
任何帮助将不胜感激。谢谢!
{
"dependencies": {
"prop-types": "15.6.2",
"react": "16.6.0-alpha.8af6728",
"react-native": "0.57.3"
},
"devDependencies": {
"babel-cli": "6.26.0",
"babel-eslint": "10.0.1",
"babel-jest": "23.6.0",
"babel-polyfill": "6.26.0",
"babel-preset-react-native": "^4.0.1",
"eslint": "5.7.0",
"jest": "23.6.0",
"jest-cli": "23.6.0",
"metro-react-native-babel-preset": "0.48.1",
"react-test-renderer": "16.6.0-alpha.8af6728"
}
}
{
"jest": {
"transform": {
"^.+\\.(js)$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"
},
"coverageDirectory": "./coverage/jest",
"collectCoverage": true,
"collectCoverageFrom": [
"src/components/**/*.js",
"src/lib/components/**/*.js",
],
"coverageThreshold": {
"global": {
"statements": 90,
"branches": 90,
"functions": 90,
"lines": 90
}
},
"preset": "react-native"
}
}
import 'react-native';
import React from 'react';
import renderer from 'react-test-renderer';
import H1 from '../../../../src/lib/components/H1';
describe('H1', () => {
it('should render correctly', () => {
const tree = renderer.create(<H1>Title</H1>).toJSON();
expect(tree).toMatchSnapshot();
});
});
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import Text from '../../containers/TextContainer.js';
import { TEXT_LIGHT } from '../colors';
export default class H1 extends Component {
static propTypes = {
children: PropTypes.node.isRequired,
color: PropTypes.string,
}
static defaultProps = {
color: TEXT_LIGHT,
}
render() {
return (
<Text
color={this.props.color}
fontSizeRatio={3.4}
>
{this.props.children}
</Text>
);
}
}
在大多数文件中,我的代码覆盖率在所有类别中均应为100%。