본문으로 건너뛰기
Skillpedia
테스트40k · #7461

unit-test-vue-pinia

하는 일

이 도구는 Vue 코드의 특정 부분에 대한 테스트를 작성하고 검토하는 데 도움을 줍니다. 테스트가 단순하고 믿을 만하며, 원하는 동작에 집중하도록 합니다.

사용하는 경우

  • ✓구성 요소, 함수, 또는 스토어(데이터를 관리하는 곳)에 대한 새 테스트를 만들 때.
  • ✓기존 테스트를 업데이트해 여전히 올바르게 작동하는지 확인할 때.
  • ✓내부 세부 사항을 신경 쓰지 않고 코드 일부가 기대대로 작동하는지 확실히 하고 싶을 때.

스킬 링크

https://github.com/github/awesome-copilot/blob/main/skills/unit-test-vue-pinia/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/github/awesome-copilot/blob/main/skills/unit-test-vue-pinia/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“유효한 자격 증명으로 사용자가 로그인할 수 있는지 확인하는 로그인 구성 요소 테스트를 작성해 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

도구는 테스트하려는 동작을 분석하고, 필요한 도구(데이터 관리를 위한 Pinia 등)를 설정하며, 결과가 기대와 맞는지 확인합니다. 사용자가 보고 상호작용하는 것에 집중하며, 코드의 내부 작동에는 집중하지 않습니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

unit-test-vue-pinia

Use this skill to create or review unit tests for Vue components, composables, and Pinia stores. Keep tests small, deterministic, and behavior-first.

Workflow

  1. Identify the behavior boundary first: component UI behavior, composable behavior, or store behavior.
  2. Choose the narrowest test style that can prove that behavior.
  3. Set up Pinia with the least powerful option that still covers the scenario.
  4. Drive the test through public inputs such as props, form updates, button clicks, emitted child events, and store APIs.
  5. Assert observable outputs and side effects before considering any instance-level assertion.
  6. Return or review tests with clear behavior-oriented names and note any remaining coverage gaps.

Core Rules

  • Test one behavior per test.
  • Assert observable input/output behavior first (rendered text, emitted events, callback calls, store state changes).
  • Avoid implementation-coupled assertions.
  • Access wrapper.vm only in exceptional cases when there is no reasonable DOM, prop, emit, or store-level assertion.
  • Prefer explicit setup in beforeEach() and reset mocks every test.
  • Use checked-in reference material in references/pinia-patterns.md as the local source of truth for standard Pinia test setups.

Pinia Testing Approach

Use references/pinia-patterns.md first, then fall back to Pinia's testing cookbook when the checked-in examples do not cover the case.

Default pattern for component tests

Use createTestingPinia as a global plugin while mounting. Prefer createSpy: vi.fn as the default for consistency and easier action-spy assertions.

const wrapper = mount(ComponentUnderTest, {
	global: {
		plugins: [
			createTestingPinia({
				createSpy: vi.fn,
			}),
		],
	},
});

By default, actions are stubbed and spied. Use stubActions: true (default) when the test only needs to verify whether an action was called (or not called).

Accepted minimal Pinia setups

The following are also valid and should not be flagged as incorrect:

  • createTestingPinia({}) when the test does not assert Pinia action spy behavior.
  • createTestingPinia({ initialState: ... }) or createTestingPinia({ stubActions: ... }) without createSpy, when the test only needs state seeding or action stubbing behavior and does not inspect generated spies.
  • setActivePinia(createTestingPinia(...)) in store/composable-focused tests (without mounting a component) when mocking/seeding dependent stores is needed.

Use createSpy: vi.fn when action spy assertions are part of the test intent.

Execute real actions only when needed

Use stubActions: false only when the test must validate the action's real behavior and side effects. Do not switch it on by default for simple "was called" assertions.

const wrapper = mount(ComponentUnderTest, {
	global: {
		plugins: [
			createTestingPinia({
				createSpy: vi.fn,
				stubActions: false,
			}),
		],
	},
});

Seed store state with initialState

const wrapper = mount(ComponentUnderTest, {
	global: {
		plugins: [
			createTestingPinia({
				createSpy: vi.fn,
				initialState: {
					counter: { n: 20 },
					user: { name: "Leia Organa" },
				},
			}),
		],
	},
});

Add Pinia plugins through createTestingPinia

const wrapper = mount(ComponentUnderTest, {
	global: {
		plugins: [
			createTestingPinia({
				createSpy: vi.fn,
				plugins: [myPiniaPlugin],
			}),
		],
	},
});

Getter override pattern for edge cases

const pinia = createTestingPinia({ createSpy: vi.fn });
const store = useCounterStore(pinia);

store.double = 999;
// @ts-expect-error test-only reset of overridden getter
store.double = undefined;

Pure store unit tests

Prefer pure store tests with createPinia() when the goal is to validate store state transitions and action behavior without component rendering. Use createTestingPinia() only when you need stubbed dependent stores, seeded test doubles, or action spies.

beforeEach(() => {
	setActivePinia(createPinia());
});

it("increments", () => {
	const counter = useCounterStore();
	counter.increment();
	expect(counter.n).toBe(1);
});

Vue Test Utils Approach

Follow Vue Test Utils guidance: https://test-utils.vuejs.org/guide/

  • Mount shallow by default for focused unit tests.
  • Mount full component trees only when integration behavior is the subject.
  • Drive behavior through props, user-like interactions, and emitted events.

…

자주 묻는 질문

'단위 테스트'란 무엇인가요?

구성 요소나 함수처럼 코드의 한 부분이 다른 부분과 떨어져서 올바르게 작동하는지 확인하는 작은 테스트입니다.

Pinia란 무엇인가요?

Vue.js 애플리케이션의 상태(데이터)를 체계적으로 관리하는 데 쓰는 도구입니다.

내부 세부 사항 대신 '동작'에 집중하는 이유는 무엇인가요?

동작을 테스트하면 주요 기능이 사용자에게 제대로 작동하는지 확인할 수 있습니다. 내부 세부 사항을 테스트하면, 최종 결과가 같더라도 내부 작동 방식을 바꿀 때 테스트가 깨질 수 있습니다.

상세 정보

작성자의 원본 설명

Write and review unit tests for Vue 3 + TypeScript + Vitest + Pinia codebases. Use when creating or updating tests for components, composables, and stores; mocking Pinia with createTestingPinia; applying Vue Test Utils patterns; and enforcing black-box assertions over implementation details.

repo: github/awesome-copilot

인기도

GitHub 스타
40k
순위
#7461
라이선스
MIT
업데이트
2026. 10. 15.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬