如何在开玩笑的酶中为对象编写测试用例?

时间:2020-05-15 08:45:59

标签: unit-testing jestjs

有人可以帮我用Jest react-typescript编写对象的单元测试用例吗?

我的文件名为home.tsx,代码如下,其中tableIcons是我的对象-

export const tableIcons = {
  Add: forwardRef((props: any, ref: any) => <AddBox {...props} {...ref} />),
  Check: forwardRef((props, ref) => <Check {...props} {...ref} />),
}

我的home.test.tsx文件如下-

import AddBox from "@material-ui/icons/AddBox";
import Check from "@material-ui/icons/Check";
import { shallow } from "enzyme";
import React, { forwardRef } from "react";

const tableIcons = {
  Add: forwardRef((props: any, ref: any) => <AddBox {...props} {...ref} />),
};
const tableIcons1 = {
  Add: forwardRef((props: any, ref: any) => <AddBox {...props} {...ref} />),
};

describe("Scenario Utils Component Rendering", () => {
  test("should test Check Component", () => {
    expect(JSON.stringify(tableIcons1)).toEqual(JSON.stringify(tableIcons));
  });
});

在这种情况下,我的测试用例通过了,但是当我检查代码覆盖率时,它仍然表示语句未覆盖且函数未覆盖。那么如何涵盖所有这些语句和函数?

0 个答案:

没有答案