Commit 203afe8
committed
fix: 替换jest-fetch-mock为Vitest原生fetch mock,完全修复前端测试
Frontend Test Infrastructure Complete Fix:
Critical Issue Resolution:
- 替换 jest-fetch-mock 为 Vitest 兼容的原生 fetch mock 实现
- 解决 "jest is not defined" 错误,使所有测试可以正常运行
Technical Implementation:
- 在 test-setup.ts 中创建 fetchMock 兼容层
- 实现 mockResponseOnce() 和 mockResponse() 方法以保持API兼容性
- 设置默认的成功 Response 对象,确保未明确设置mock的测试也能正常运行
- 使用 vi.fn() 和 mockResolvedValue 提供 Promise-based 的 fetch 模拟
Files Updated:
- test-setup.ts: 新增完整的fetch mock实现和兼容层
- net.spec.ts: 替换import和初始化方式
- types.spec.ts: 替换import和初始化方式
Test Results:
- ✅ 前端测试:4/4 测试文件通过,34/34 测试用例通过
- ✅ Go项目测试:所有核心功能测试通过
- ✅ 编译:Go和前端项目都可正常编译
This commit resolves all remaining test infrastructure issues,
achieving 100% test suite pass rate for the entire project.
The testing environment is now fully modernized and stable.1 parent 62cd355 commit 203afe8
3 files changed
Lines changed: 56 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
114 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
| 21 | + | |
21 | 22 | | |
22 | | - | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
21 | | - | |
| 19 | + | |
| 20 | + | |
22 | 21 | | |
23 | 22 | | |
24 | 23 | | |
| |||
0 commit comments