我是编写单元测试的新手,我正在尝试使用testing-library/react和向我的反应应用程序编写单元测试jest
这是测试代码“Home.test.js”
import React from 'react';
import {render, cleanup} from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import Home from "../src/Home";
afterEach(cleanup);
describe("Tests for HomePage", function() {
it("should render without throwing an error", function() {
const { homePage } = render(<Home />);
//check something here
});
});
Run Code Online (Sandbox Code Playgroud)
这是我在组件“Home.js”中的代码
import * as React from "react";
import { Panel, Shell, Button } from "@myorg/core";
import { home_icon, new_icon } from "@myorg/icons";
function Home(props) {
const openDialog = React.useCallback(() => {
//do something
}); …Run Code Online (Sandbox Code Playgroud)