2
0

debug.test.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { describe, it, expect, vi } from 'vitest';
  2. import { render, screen } from '@testing-library/react';
  3. import { TestWrapper } from '@/client/__test_utils__/test-render';
  4. import { UsersPage } from '../Users';
  5. import { userClient } from '@/client/api';
  6. // Mock the API client
  7. vi.mock('@/client/api', () => ({
  8. userClient: {
  9. $get: vi.fn(),
  10. $post: vi.fn(),
  11. ':id': {
  12. $put: vi.fn(),
  13. $delete: vi.fn()
  14. }
  15. }
  16. }));
  17. describe('Debug Test', () => {
  18. it('should mock the API client', async () => {
  19. // Mock the API call
  20. (userClient.$get as any).mockResolvedValue({
  21. status: 200,
  22. ok: true,
  23. json: async () => ({
  24. data: [
  25. {
  26. id: 1,
  27. username: 'testuser',
  28. nickname: '测试用户',
  29. email: 'test@example.com',
  30. phone: '13800138000',
  31. name: '测试用户',
  32. isDisabled: 0,
  33. createdAt: '2024-01-01T00:00:00.000Z',
  34. roles: [{ id: 1, name: 'admin' }]
  35. }
  36. ],
  37. pagination: {
  38. total: 1,
  39. current: 1,
  40. pageSize: 10
  41. }
  42. })
  43. });
  44. render(
  45. <TestWrapper>
  46. <UsersPage />
  47. </TestWrapper>
  48. );
  49. // Check if the mock was called
  50. expect(userClient.$get).toHaveBeenCalled();
  51. // Wait for data to load
  52. await screen.findByText('testuser');
  53. expect(screen.getByText('testuser')).toBeInTheDocument();
  54. });
  55. });