230913(μ)
π€ μ±μ₯μΌμ§ 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',
},
];
π νκ³
μκ³ μ€λμ λΉ λ₯΄κ² λ―Έμ μ 리νκ³ λ₯μ€νΈ κ°μλ λ£κ³ μΆμλλ°, μκ°λ³΄λ€ λ―Έμ μ 리νλλ° μκ°μ΄ μ€λ κ±Έλ Έλ€. μ’λ λΉ λ¦Ώνκ²(μ§κΈλ³΄λ€ λ..?) μμ§μ¬μΌμ§!!!