0

我很新的反应,我正在努力提高代码覆盖率。我使用了一些链接来使用 spyon 来测试我的钩子,但测试通过了,但覆盖率没有提高。请求您的帮助。

这是我们的示例代码

import SimplePage from "../SimplePage/SimplePage";
import { useContext } from "react";
import { UrlContext } from "../../../../App";
export default function Degumming() {
  const apiRootUrl = useContext(UrlContext);
  return SimplePage({
    endpointUrl: apiRootUrl + "/api/simple/parameters/degumming/",
    tableTitle: "Degumming Table of ",
    columnsTitle: [
      ["stock Name", 1],
      ["Degumming", 1],
      ["", 1],
    ],
  });
}

这是样本测试

import React from 'react';
import { shallow } from 'enzyme';
import Degumming from './Degumming';
import { Provider } from 'react-redux';
import { store } from '../../../../redux/Index';
describe('<Degumming />', () => {
    test("Test Simple Page render", () => {
        const apiRootURL =  "/api/simple/parameters/degumming/";
        jest.spyOn(React, 'useContext')
        .mockImplementation(() => apiRootURL);
        const wrapper = shallow(<Provider store={store}><Degumming /></Provider>);
        expect(wrapper.find('Generate Inputs')).toHaveBeenCalled();
      });
});

我究竟做错了什么 :(

4

0 回答 0