创建React App测试覆盖率报告未涵盖/ src中的所有文件

时间:2020-04-29 17:33:53

标签: reactjs jestjs enzyme create-react-app react-scripts

使用npx create-react-app my-app创建应用程序。使用伊斯坦布尔(Istanbul)生成的html文件检查时,npm test -- --coverage的运行覆盖率报告不会覆盖文件夹/src内的所有文件,即 project> coverage> lcov-报告> index.html ,但使用npm test -- --coverage --watchAll=false 覆盖 /src文件夹中的所有文件,但失败组件呈现测试,并出现以下错误:

Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.

以下是项目详细信息:

Login.js

import React from "react";
import { withRouter } from "react-router";
export class Login extends React.Component {
  constructor(props) {
    super(props);
  }

  render() {
    return (
      <div className="page-login bg-img">
           ...
      </div>
      );
  }
}

const NewLogin = withRouter(Login);
export default NewLogin;

Login.test.js

import { render } from "enzyme";
import {Login} from "./components/Login"
describe(`Login page`, () => {
  it(`Login renders`, () => {
    render(<Login />);
  });
});

Package.json

"react": "^16.13.1",
"react-scripts": "^3.4.1",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.2",

请帮助,我是新来的单元测试人员。提前致谢。

0 个答案:

没有答案