agentsclimarketplace

Testing

Skill DaleStudy/skills/skills/testing

๐Ÿ› ๏ธ ์—์ด์ „ํŠธ ์Šคํ‚ฌ

Install
npx -y skills add DaleStudy/skills --skill testing

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 4 stars4 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

React Testing Library ๋ฐ Vitest ๊ธฐ๋ฐ˜ ํ…Œ์ŠคํŒ… ๋ชจ๋ฒ” ๊ด€๋ก€. ๋‹ค์Œ ์ƒํ™ฉ์—์„œ ์‚ฌ์šฉ: (1) .test.tsx, .test.ts, .spec.tsx, .spec.ts ํŒŒ์ผ ์ž‘์—… ์‹œ, (2) ์ปดํฌ๋„ŒํŠธ ํ…Œ์ŠคํŠธ ์ž‘์„ฑ ๋˜๋Š” ๋ฆฌํŒฉํ† ๋ง ์‹œ, (3) 'test', 'testing', 'vitest', 'RTL', 'getByRole', 'userEvent', 'waitFor', 'expect' ํ‚ค์›Œ๋“œ ํฌํ•จ ์ž‘์—… ์‹œ, (4) ๋น„๋™๊ธฐ ๋กœ์ง ๋˜๋Š” ์‚ฌ์šฉ์ž ์ƒํ˜ธ์ž‘์šฉ ํ…Œ์ŠคํŠธ ์ž‘์„ฑ ์‹œ

The file declares its own license as MIT. That is the authorโ€™s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

6.2 KB, as published. Nobody here has run it

Testing Library

React Testing Library ๊ธฐ๋ฐ˜ ํ…Œ์ŠคํŠธ ์ž‘์„ฑ ๋ชจ๋ฒ” ๊ด€๋ก€ ๋ฐ ์•ˆํ‹ฐํŒจํ„ด ํšŒํ”ผ ๊ฐ€์ด๋“œ.

ํ•ต์‹ฌ ์›์น™

Testing Library์˜ ์ฒ ํ•™: ์‚ฌ์šฉ์ž๊ฐ€ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ์‹๋Œ€๋กœ ํ…Œ์ŠคํŠธํ•˜๋ผ

  1. ์ ‘๊ทผ์„ฑ ๊ธฐ๋ฐ˜ ์ฟผ๋ฆฌ ์šฐ์„  - ์‹ค์ œ ์‚ฌ์šฉ์ž๊ฐ€ ์š”์†Œ๋ฅผ ์ฐพ๋Š” ๋ฐฉ์‹ ์‚ฌ์šฉ
  2. ๊ตฌํ˜„ ์„ธ๋ถ€์‚ฌํ•ญ ํ…Œ์ŠคํŠธ ๊ธˆ์ง€ - ์ปดํฌ๋„ŒํŠธ ๋‚ด๋ถ€ ์ƒํƒœ/๋ฉ”์„œ๋“œ ์ง์ ‘ ์ ‘๊ทผ ์ง€์–‘
  3. ์‹ค์ œ ์‚ฌ์šฉ์ž ํ–‰๋™ ์‹œ๋ฎฌ๋ ˆ์ด์…˜ - userEvent ์‚ฌ์šฉ, fireEvent ์ง€์–‘
  4. ๋น„๋™๊ธฐ ์ฒ˜๋ฆฌ ๋ช…์‹œ์  ๋Œ€๊ธฐ - waitFor, findBy ํ™œ์šฉ

์ฟผ๋ฆฌ ์šฐ์„ ์ˆœ์œ„

Testing Library๋Š” ๋‹ค์–‘ํ•œ ์ฟผ๋ฆฌ๋ฅผ ์ œ๊ณตํ•˜์ง€๋งŒ, ์ ‘๊ทผ์„ฑ๊ณผ ์‚ฌ์šฉ์ž ๊ฒฝํ—˜์„ ๋ฐ˜์˜ํ•˜๋Š” ์ˆœ์„œ๋กœ ์‚ฌ์šฉํ•ด์•ผ ํ•จ.

๊ถŒ์žฅ ์ฟผ๋ฆฌ ์ˆœ์„œ (๋†’์Œ โ†’ ๋‚ฎ์Œ)

  1. getByRole (์ตœ์šฐ์„ ) - ์Šคํฌ๋ฆฐ ๋ฆฌ๋”๊ฐ€ ์ธ์‹ํ•˜๋Š” ๋ฐฉ์‹
  2. getByLabelText - ํผ ์š”์†Œ (label๊ณผ ์—ฐ๊ฒฐ๋œ input)
  3. getByPlaceholderText - placeholder๊ฐ€ ๋ช…ํ™•ํ•œ ๊ฒฝ์šฐ
  4. getByText - ํ…์ŠคํŠธ ์ฝ˜ํ…์ธ ๋กœ ๊ฒ€์ƒ‰
  5. getByDisplayValue - ํ˜„์žฌ ์ž…๋ ฅ๋œ ๊ฐ’์œผ๋กœ ๊ฒ€์ƒ‰ (ํผ ์š”์†Œ)
  6. getByAltText - ์ด๋ฏธ์ง€ alt ์†์„ฑ
  7. getByTitle - title ์†์„ฑ (tooltip ๋“ฑ)
  8. getByTestId (์ตœํ›„ ์ˆ˜๋‹จ) - ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์ด ๋ถˆ๊ฐ€๋Šฅํ•  ๋•Œ๋งŒ ์‚ฌ์šฉ

์ƒ์„ธ ๊ฐ€์ด๋“œ: references/query-priority.md

์‚ฌ์šฉ์ž ์ƒํ˜ธ์ž‘์šฉ ํ…Œ์ŠคํŠธ

userEvent ์‚ฌ์šฉ (๊ถŒ์žฅ)

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

test('์‚ฌ์šฉ์ž๊ฐ€ ํผ์„ ์ œ์ถœํ•  ์ˆ˜ ์žˆ๋‹ค', async () => {
  const user = userEvent.setup();
  render(<LoginForm />);

  await user.type(screen.getByRole('textbox', { name: /์ด๋ฉ”์ผ/i }), '[email protected]');
  await user.type(screen.getByLabelText(/๋น„๋ฐ€๋ฒˆํ˜ธ/i), 'password123');
  await user.click(screen.getByRole('button', { name: /๋กœ๊ทธ์ธ/i }));

  expect(await screen.findByText(/ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค/i)).toBeInTheDocument();
});

ํ•ต์‹ฌ:

  • userEvent.setup() ํ˜ธ์ถœ ํ›„ ์‚ฌ์šฉ
  • ๋ชจ๋“  user ๋ฉ”์„œ๋“œ๋Š” await ํ•„์ˆ˜
  • ์‹ค์ œ ๋ธŒ๋ผ์šฐ์ € ์ด๋ฒคํŠธ ์ˆœ์„œ ์žฌํ˜„ (focus, keydown, keyup ๋“ฑ)

fireEvent ์ง€์–‘

// โŒ ๋‚˜์œ ์˜ˆ - fireEvent ์‚ฌ์šฉ
fireEvent.click(button);
fireEvent.change(input, { target: { value: "text" } });

// โœ… ์ข‹์€ ์˜ˆ - userEvent ์‚ฌ์šฉ
await user.click(button);
await user.type(input, "text");

์ƒ์„ธ ๊ฐ€์ด๋“œ: references/user-events.md

๋น„๋™๊ธฐ ์ฒ˜๋ฆฌ

findBy ์ฟผ๋ฆฌ (๊ถŒ์žฅ)

// โœ… ์ข‹์€ ์˜ˆ - findBy ์‚ฌ์šฉ
const successMessage = await screen.findByText(/์ €์žฅ๋˜์—ˆ์Šต๋‹ˆ๋‹ค/i);
expect(successMessage).toBeInTheDocument();

findBy = getBy + waitFor ์กฐํ•ฉ (์ž๋™์œผ๋กœ ์š”์†Œ ๋‚˜ํƒ€๋‚  ๋•Œ๊นŒ์ง€ ๋Œ€๊ธฐ)

waitFor ์‚ฌ์šฉ

// ๋ณต์žกํ•œ ๋น„๋™๊ธฐ ๊ฒ€์ฆ
await waitFor(() => {
  expect(screen.getByRole("alert")).toHaveTextContent("์„ฑ๊ณต");
});

// ์—ฌ๋Ÿฌ ์กฐ๊ฑด ๊ฒ€์ฆ
await waitFor(() => {
  expect(mockFn).toHaveBeenCalledTimes(1);
  expect(screen.queryByText(/๋กœ๋”ฉ ์ค‘/i)).not.toBeInTheDocument();
});

์•ˆํ‹ฐํŒจํ„ด

// โŒ ๋‚˜์œ ์˜ˆ - ์ž„์˜์˜ timeout
await new Promise((resolve) => setTimeout(resolve, 1000));

// โŒ ๋‚˜์œ ์˜ˆ - act() ์ˆ˜๋™ ์‚ฌ์šฉ (๋ณดํ†ต ๋ถˆํ•„์š”)
await act(async () => {
  // ...
});

// โœ… ์ข‹์€ ์˜ˆ - findBy ๋˜๋Š” waitFor
await screen.findByText(/์™„๋ฃŒ/i);

์ƒ์„ธ ๊ฐ€์ด๋“œ: references/async-patterns.md

์ž์ฃผ ํ•˜๋Š” ์‹ค์ˆ˜

1. ๊ตฌํ˜„ ์„ธ๋ถ€์‚ฌํ•ญ ํ…Œ์ŠคํŠธ

// โŒ ๋‚˜์œ ์˜ˆ - ๋‚ด๋ถ€ ์ƒํƒœ ์ ‘๊ทผ
expect(component.state.isOpen).toBe(true);
wrapper.find(".internal-class").simulate("click");

// โœ… ์ข‹์€ ์˜ˆ - ์‚ฌ์šฉ์ž ๊ด€์  ๊ฒ€์ฆ
expect(screen.getByRole("dialog")).toBeVisible();
await user.click(screen.getByRole("button", { name: /์—ด๊ธฐ/i }));

2. container ์ฟผ๋ฆฌ ์‚ฌ์šฉ

// โŒ ๋‚˜์œ ์˜ˆ - container.querySelector
const { container } = render(<MyComponent />);
const button = container.querySelector('.my-button');

// โœ… ์ข‹์€ ์˜ˆ - screen ์ฟผ๋ฆฌ
const button = screen.getByRole('button', { name: /์ œ์ถœ/i });

3. ๋ถˆํ•„์š”ํ•œ waitFor

// โŒ ๋‚˜์œ ์˜ˆ - ๋™๊ธฐ ์š”์†Œ์— waitFor
await waitFor(() => {
  expect(screen.getByText("Hello")).toBeInTheDocument();
});

// โœ… ์ข‹์€ ์˜ˆ - ๋™๊ธฐ ์š”์†Œ๋Š” ์ฆ‰์‹œ ๊ฒ€์ฆ
expect(screen.getByText("Hello")).toBeInTheDocument();

4. getBy* + toBeInTheDocument() ์ œ๊ฑฐ

getBy*๋Š” ์š”์†Œ๋ฅผ ๋ชป ์ฐพ์œผ๋ฉด throwํ•˜๋ฏ€๋กœ toBeInTheDocument()๋Š” ๊ธฐ์ˆ ์ ์œผ๋กœ ์ค‘๋ณต์ด๋‹ค. ํ•˜์ง€๋งŒ ์ œ๊ฑฐํ•˜์ง€ ๋งˆ๋ผ โ€” ๋ฆฌํŒฉํ† ๋ง ํ›„ ๋‚จ์€ ์ฟผ๋ฆฌ๊ฐ€ ์•„๋‹ˆ๋ผ ์˜๋„์ ์ธ ์กด์žฌ ๊ฒ€์ฆ์ž„์„ ์ฝ”๋“œ ๋…์ž์—๊ฒŒ ์ „๋‹ฌํ•˜๋Š” ์—ญํ• ์„ ํ•œ๋‹ค.

// โŒ ๋‚˜์œ ์˜ˆ - assertion ์—†์ด ์ฟผ๋ฆฌ๋งŒ ๋‚จ๊น€
screen.getByRole("button", { name: /์ œ์ถœ/i });

// โœ… ์ข‹์€ ์˜ˆ - ๋ช…์‹œ์  assertion์œผ๋กœ ์˜๋„ ์ „๋‹ฌ
expect(screen.getByRole("button", { name: /์ œ์ถœ/i })).toBeInTheDocument();

๋‹จ, ์กด์žฌ ๊ฒ€์ฆ์ด ์•„๋‹Œ ๋‹ค๋ฅธ ์†์„ฑ์„ ๊ฒ€์ฆํ•  ๋•Œ๋Š” toBeInTheDocument()๋ฅผ ์ถ”๊ฐ€ํ•  ํ•„์š” ์—†๋‹ค:

// โœ… ์ข‹์€ ์˜ˆ - ๋‹ค๋ฅธ matcher๋กœ ์ถฉ๋ถ„
expect(screen.getByRole("button", { name: /์ œ์ถœ/i })).toBeDisabled();

// โŒ ๋‚˜์œ ์˜ˆ - ์ค‘๋ณต assertion
expect(screen.getByRole("button", { name: /์ œ์ถœ/i })).toBeInTheDocument();
expect(screen.getByRole("button", { name: /์ œ์ถœ/i })).toBeDisabled();

์ „์ฒด ์•ˆํ‹ฐํŒจํ„ด ๋ชฉ๋ก: references/common-mistakes.md

Vitest + MSW ์„ค์ •

ํ…Œ์ŠคํŠธ ํ™˜๊ฒฝ ์„ค์ •์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ ๋‹ค์Œ ํ…œํ”Œ๋ฆฟ ์ฐธ์กฐ:

  • assets/vitest.config.ts - Vitest ์„ค์ • (React ํ”Œ๋Ÿฌ๊ทธ์ธ, ์ปค๋ฒ„๋ฆฌ์ง€ ํฌํ•จ)
  • assets/test-setup.ts - Vitest ๊ธ€๋กœ๋ฒŒ ์„ค์ •
  • assets/msw-setup.ts - MSW ํ•ธ๋“ค๋Ÿฌ ๋ฐ ์„œ๋ฒ„ ์„ค์ •

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.