【发布时间】:2021-11-13 18:30:39
【问题描述】:
我对测试反应应用程序完全陌生。我想知道是否需要测试每个组件在不崩溃的情况下呈现,还是只测试 App 组件就足够了,因为它是所有组件的父级?
此外,任何提示以及在组件中测试的内容都会很棒:)
import { render } from "@testing-library/react";
import App from "./App";
// Test that the App Component renders without crashing
describe("App", () => {
test("renders App component", () => {
render(<App />);
});
});
例如,在另一个组件中,我会做以下测试:
import { render } from "@testing-library/react";
import App from "./App";
// Test that the AnotherComp Component renders without crashing
describe("AnotherComp", () => {
test("renders App component", () => {
render(<AnotherComp/>);
});
});
【问题讨论】:
标签: reactjs testing react-testing-library