React에서 Jest를 사용할 때 describe, it, expect
를 따로 import하지 않아도 된다. 하지만 인식이 되지 않아 잠시 방황했다 😅
$ npm i -D jest
$ yarn add --dev jest
"devDependencies": {
"@testing-library/react": "^13.4.0",
"@testing-library/jest-dom": "^5.16.5",
"@types/jest": "^29.2.2",
"jest": "^29.3.1"
}
.eslintrc.json
에 jest
옵션 추가 "env":{
"jest": true
}
fn + F1
을 누르고 ESlint: Restart
& Developer: Reload
실행module.exports = {
presets: ["@babel/preset-env", "@babel/preset-react", '@babel/preset-typescript'],
};
"jest": {
"testEnvironment": "jsdom"
}
import { render } from "@testing-library/react";
import "@testing-library/jest-dom";
import { render, screen } from "@testing-library/react";
import QuizOption from "../QuizOption";
import React from "react";
import theme from "../../styles/theme";
import { ThemeProvider } from "styled-components";
const QuizOptionProps = {
index: 1,
content: "테스트 문항입니다.",
isAnswer: true,
};
describe("QuizOption", () => {
it("선택지에 문구가 나오는지 확인", () => {
render(
<ThemeProvider theme={theme}> // 🚨 추가 🚨
<QuizOption {...QuizOptionProps} />
</ThemeProvider>
);
const text = screen.getByText("content");
expect(text).toBeInTheDocument();
});
});