Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✅ test: storeのテストを実装 #49

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/test/unit/store/sampleStore.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { setActivePinia, createPinia } from 'pinia';
import { beforeEach, describe, expect, it } from 'vitest';
import { useSampleStore } from '@/store/sampleStore';

describe('sampleStore', () => {
let sampleStore: ReturnType<typeof useSampleStore>;

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

describe('getters', () => {
it('getCountが初期のカウントを返すこと', () => {
expect(sampleStore.getCount).toBe(0);
sampleStore.increment();
expect(sampleStore.getCount).toBe(1);
});

it('getCount2がカウントに2を加えること', () => {
expect(sampleStore.getCount2).toBe(2);
});

it('getCount3が指定された数をカウントに加えること', () => {
expect(sampleStore.getCount3(3)).toBe(3);
});

it('getCount4が指定された数をカウントに加えること', () => {
expect(sampleStore.getCount4(4)).toBe(4);
});

it('getCount5が指定された数をカウントに加え、状態を変更すること', () => {
expect(sampleStore.getCount5(5)).toBe(10);
expect(sampleStore.count).toBe(5);
});

it('getCount6が指定された数をカウントに加え、状態を変更すること', () => {
expect(sampleStore.getCount6(6)).toBe(12);
expect(sampleStore.count).toBe(6);
});
});
XeicuLy marked this conversation as resolved.
Show resolved Hide resolved

describe('actions', () => {
it('incrementでカウントが増加すること', () => {
expect(sampleStore.count).toBe(0);
sampleStore.increment();
expect(sampleStore.count).toBe(1);
});

it('decrementでカウントが減少すること', () => {
expect(sampleStore.count).toBe(0);
sampleStore.decrement();
expect(sampleStore.count).toBe(-1);
});
});
});