toHaveTextContent ์์ ์๋ฌ๊ฐ ์๊พธ ๋๋๋ฐ ์๋ฌด๋ฆฌ ์ฐพ์๋ ์ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค.
์ด์ ์ ํด๊ฒฐํ์ง ๋ชปํ ๋ฌธ์ ์์ง๋ง, ๋ณต์ต์ ํ๋ฉด์ ํด๊ฒฐํ์ต๋๋ค.ํน์ ์ ์ ๊ฐ์ ์ค๋ฅ๋ฅผ ๊ฒช์ผ์ ๋ถ๋ค๊ป ๋์์ด ๋ ๊น ์ถ์ด ํด๊ฒฐ ๋ฐฉ๋ฒ์ ๋จ๊ฒจ๋ด
๋๋ค.toHaveTextContent์ ์ค๋ฅ๋ผ ์๊ฐํ ๋ฌธ์ ๋ ์ฌ์ค userEvent๊ฐ ์ ๋๋ก ์๋ํ์ง ์์ ๋ฐ์ํ ๋ฌธ์ ์์ต๋๋ค.๊ณต์๋ฌธ์์ ๋ณด๋ฉด, userEvent.setup()์ ํธ์ถํด ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ์ถ์ฒํ๊ณ ์์ต๋๋ค. ์ ๋ ์ด๋ ๊ฒ ๋ถ๋ฌ์ด์ผ๋ก ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์ต๋๋ค.We recommend invoking userEvent.setup() before the component is rendered.https://testing-library.com/docs/user-event/intro///package.json "@testing-library/user-event": "^14.4.3"import { render, screen } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { OrderContextProvider } from "../../../contexts/OrderContext"; import Type from "../Type"; test("update product's total when products change", async () => { โ
const event = userEvent.setup(); render(, { wrapper: OrderContextProvider }); const productsTotal = screen.getByText("์ด ๊ฐ๊ฒฉ:", { exact: false }); expect(productsTotal).toHaveTextContent("0"); //์๋ฉ๋ฆฌ์นด ์ฌํ ์ํ ํ ๊ฐ ์ฌ๋ฆฌ๊ธฐ const americaInput = await screen.findByRole("spinbutton", { name: "America", }); โ
await event.clear(americaInput); โ
await event.type(americaInput, "1"); expect(productsTotal).toHaveTextContent("1000"); });