Test Driven Development (TDD)
TDD의 장점
React Testing Library (RTL)
Jest
Jest 파일 구조
render 함수
쿼리 함수
matcher를 알맞게 쓰는지 확인하거나 문법을 올바르게 쓰는지 도와주는 모듈 : ESLint, Prettier
ESLint Testing Plugins
import { render, screen, fireEvent } from "@testing-library/react"; import App from "./App"; test("the counter starts at 0", () => { render(<App />); //screen object를 이용해서 원하는 엘레멘트에 접근(접근할 때 ID로) const counterElement = screen.getByTestId("counter"); // id가 counter인 엘레멘트의 텍스트가 0인지 테스트 expect(counterElement).toHaveTextContent(0); }); test("minus button has correct text", () => { render(<App />); const minusButtonElement = screen.getByTestId("minus-button"); expect(minusButtonElement).toHaveTextContent("-"); }); test("plus button has correct text", () => { render(<App />); const plusButtonElement = screen.getByTestId("plus-button"); expect(plusButtonElement).toHaveTextContent("+"); }); // fireEvent를 이용해서 클릭관리 test("When the + button is pressed, the counter changes to 1", () => { render(<App />); const buttonElement = screen.getByTestId("plus-button"); fireEvent.click(buttonElement); const counterElement = screen.getByTestId("counter"); expect(counterElement).toHaveTextContent(1); }); test("When the - button is pressed, the counter changes to -1", () => { render(<App />); const buttonElement = screen.getByTestId("minus-button"); fireEvent.click(buttonElement); const counterElement = screen.getByTestId("counter"); expect(counterElement).toHaveTextContent(-1); }); // style은 toHaveStyle로 Test test("on/off button has blue color", () => { render(<App />); const buttonElement = screen.getByTestId("on/off-button"); expect(buttonElement).toHaveStyle({ backgroundColor: "blue" }); }); test("Prevent the -,+ button from being pressed when the on/off button is cliecked", () => { render(<App />); const onOffButtonElement = screen.getByTestId("on/off-button"); fireEvent.click(onOffButtonElement); const plusButtonElement = screen.getByTestId("plus-button"); expect(plusButtonElement).toBeDisabled(); });
Github Action을 이용한 AWS S3로 앱 자동 배포
앱배포를 위한 AWS S3 버킷 생성하기
AWS S3 버킷 설정 및 애플리케이션 배포하기
S3로 앱 자동 배포를 위한 yml 파일 완성하기