690522:0839 227 #02
CI / CD Pipeline / build (push) Successful in 5m27s
CI / CD Pipeline / deploy (push) Successful in 5m18s

This commit is contained in:
2026-05-22 08:39:26 +07:00
parent f47363c24a
commit 2e50bcaa58
8 changed files with 40 additions and 21 deletions
+4 -2
View File
@@ -1,6 +1,7 @@
// File: frontend/hooks/__tests__/use-ai-chat.test.ts
// Change Log:
// - 2026-05-19: สร้าง Unit Test สำหรับ useAiChat Hook
// - 2026-05-22: แก้ act() warning ใน test ล้างประวัติ — ใช้ async act() แทน sync
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { renderHook, waitFor, act } from '@testing-library/react';
@@ -65,8 +66,9 @@ describe('useAiChat hook', () => {
it('ควรสามารถล้างประวัติการสนทนาได้', async () => {
const { wrapper } = createTestQueryClient();
const { result } = renderHook(() => useAiChat(mockContext), { wrapper });
act(() => {
result.current.sendMessage('สวัสดี');
// ใช้ async act() เพื่อให้ React flush state updates จาก sendMessage (Promise) ได้ครบ
await act(async () => {
void result.current.sendMessage('สวัสดี');
});
act(() => {
result.current.clearHistory();