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

✨ 피드 북마크 API 연동 #52

Merged
merged 15 commits into from
May 13, 2024
Merged
43 changes: 43 additions & 0 deletions src/features/feed-bookmark/test/useBookmarks.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { renderHook, act, waitFor } from '@testing-library/react';
import { expect, test, vi } from 'vitest';

import * as bookmarkModule from '@/shared/axios';
import { createQueryClientWrapper } from '@/shared/tests';

import { useBookmarks } from '../api';

test('북마크 상태가 아닐 때, 북마크 버튼을 클릭하면 북마크 요청이 발생한다.', async () => {
// given
// requestLikeFeed 함수를 스파이한다.
const spy = vi.spyOn(bookmarkModule, 'requestBookmarkFeed');
const { result } = renderHook(() => useBookmarks(1, false), {
wrapper: createQueryClientWrapper(),
});

// requestLikeFeed가 호출되지 않았는지 확인
await waitFor(() => expect(spy).not.toHaveBeenCalled());

// when
// 좋아요 버튼 클릭
await act(async () => result.current.handleBookmarkFeed());

// then
// requestLikeFeed가 호출되었는지 확인
await waitFor(() => expect(spy).toHaveBeenCalled());
});

test('북마크 상태일 때, 북마크 버튼을 클릭하면 북마크 취소 요청이 발생한다.', async () => {
// given
const spy = vi.spyOn(bookmarkModule, 'requestUnbookmarkFeed');
const { result } = renderHook(() => useBookmarks(1, true), {
wrapper: createQueryClientWrapper(),
});

await waitFor(() => expect(spy).not.toHaveBeenCalled());

// when
await act(async () => result.current.handleBookmarkFeed());

// then
await waitFor(() => expect(spy).toHaveBeenCalled());
});
Loading