🚀 μ„±μž₯일지 7.0

μ±… ν–‰λ³΅ν•œ 이기주의자(웨인 닀이어)의 λ‚΄μš©μ— μžκ·Ήλ°›μ•„ μ‹œμž‘ν•˜λŠ” μ†Œλ°•ν•œ μ„±μž₯기둝

μ‚΄μ•„μžˆλŠ” 꽃과 죽은 꽃은 μ–΄λ–»κ²Œ κ΅¬λ³„ν•˜λŠ”κ°€?
μ„±μž₯ν•˜κ³  μžˆλŠ” 것이 μ‚΄μ•„ μžˆλŠ” 것이닀.
생λͺ…μ˜ μœ μΌν•œ μ¦κ±°λŠ” μ„±μž₯이닀!

βš› (7.0)<μ™„μ „ 개편> 파인만 ν•™μŠ΅λ²•μ„ μ•Œκ²Œ 된만큼, μ„±μž₯μΌμ§€λŠ” 정말 κ·Έ λ‚ μ˜ ν‚€μ›Œλ“œ μ€‘μ‹¬μœΌλ‘œ κ°„λ‹¨ν•˜κ²Œ μ •λ¦¬ν•˜λ„λ‘ ν•œλ‹€.

βš›οΈ ν‚€μ›Œλ“œ: 직관적이고 쉽고 κ°„λ‹¨ν•˜κ²Œ μž‘μ„±

Cypress

  • E2E ν…ŒμŠ€νŠΈλ₯Ό μœ„ν•œ 라이브러리.
  • Jestμ™€λŠ” 달리 CypressλŠ” λΈŒλΌμš°μ €μ—μ„œ λ™μž‘ν•œλ‹€.
  • 보톡 μœ μ €μ˜ 행동을 ν…ŒμŠ€νŠΈν•˜κΈ° μœ„ν•΄ μ‚¬μš©ν•œλ‹€.

였늘 jest와 RTL둜 각 μ»΄ν¬λ„ŒνŠΈ λ‹¨μœ„μ˜ ν…ŒμŠ€νŠΈ μ½”λ“œλ₯Ό μž‘μ„±ν•˜κ³  Cypress둜 κ°„λ‹¨ν•œ μœ μ €μ˜ 행동 양식에 λ§žλŠ” E2E ν…ŒμŠ€νŠΈ μ½”λ“œλ₯Ό μž‘μ„±ν–ˆλ‹€. Cypress μžμ²΄κ°€ λΈŒλΌμš°μ € UI λ‹¨μ—μ„œ μ‹€μ œ μœ μ €μ˜ μ•‘μ…˜μ„ λ³΄μ—¬μ€€λ‹€λŠ” μ μ—μ„œλŠ” μ’‹μ§€λ§Œ, jest와 RTL λ§ŒμœΌλ‘œλ„ κ°„λ‹¨ν•œ μœ μ € 행동은 ν…ŒμŠ€νŒ…ν•  수 μžˆλŠ” 것 κ°™μ•„μ„œ Cypress의 νš¨μœ¨μ„±μ— λŒ€ν•΄μ„œλŠ” 의문이 λ“ λ‹€.

Test μ½”λ“œ 양식

λ©˜ν† λ‹˜κ»˜μ„œ κ°€λ₯΄μ³μ£Όμ‹  λŒ€λ‘œ ν…ŒμŠ€νŠΈ μ½”λ“œλ§ˆλ‹€ setup ν•¨μˆ˜λ₯Ό λ‘κ³ μ„œ μ½”λ“œλ₯Ό μž‘μ„±ν•˜λ‹ˆ, 훨씬 κ°„κ²°ν•˜κ³  깔끔해진닀. μ•„λž˜λŠ” 였늘 μž‘μ„±ν•œ Chips μ»΄ν¬λ„ŒνŠΈμ— λŒ€ν•œ ν…ŒμŠ€νŠΈ μ½”λ“œμ΄λ‹€.

import React from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import '@testing-library/jest-dom';

import { Chips } from '.';
import { ThemeProvider } from 'styled-components';
import { theme } from '../../../styles/theme.styled';

describe('Chips', () => {
  it('should render Chips component', () => {
    const { chips } = setup();

    expect(chips).toBeInTheDocument();
  });
});

describe('Chip', () => {
  it('should render Chip component', () => {
    const { chipList } = setup();
    const firstChip = chipList[0];

    expect(firstChip).toBeInTheDocument();
  });

  it('should render Chip components as many as the number of data', () => {
    const { chipList } = setup();

    expect(chipList.length).toBe(mockData.length);
  });

  it('should event handler be called when click Chip component', () => {
    const { chipList } = setup();
    const firstChip = chipList[0];
    const mockOnClick = jest.fn();
    firstChip.onclick = mockOnClick;
    userEvent.click(firstChip);

    expect(mockOnClick).toHaveBeenCalled();
  });
});

const setup = () => {
  const { container } = render(
    <Chips>
      {mockData.map((data) => (
        <Chips.Chip key={data.id}>{data.name}</Chips.Chip>
      ))}
    </Chips>,
    {
      wrapper: ({ children }) => <ThemeProvider theme={theme}>{children}</ThemeProvider>,
    },
  );

  const chips = container.querySelector('section');
  const chipList = screen.getAllByRole('button');

  return {
    chips,
    chipList,
  };
};

const mockData = [
  {
    id: '0',
    name: 'test-0',
  },
  {
    id: '1',
    name: 'test-1',
  },
];

πŸ“ 회고

μ•„κ³  μ˜€λŠ˜μ€ λΉ λ₯΄κ²Œ λ―Έμ…˜ μ •λ¦¬ν•˜κ³  λ„₯슀트 κ°•μ˜λ„ λ“£κ³  μ‹Άμ—ˆλŠ”λ°, 생각보닀 λ―Έμ…˜ μ •λ¦¬ν•˜λŠ”λ° μ‹œκ°„μ΄ 였래 κ±Έλ Έλ‹€. 쒀더 λΉ λ¦Ών•˜κ²Œ(μ§€κΈˆλ³΄λ‹€ 더..?) 움직여야지!!!

μ°Έκ³