Instructions
- Following Playwright test failed.
- Explain why, be concise, respect Playwright best practices.
- Provide a snippet of code with the fix, if possible.
Test info
- Name: regression\04-favorites.spec.ts >> 收藏功能 (Favorites) >> F03: 取消收藏 DELETE /api/favorites/:id
- Location: regression\04-favorites.spec.ts:22:7
Error details
Error: expect(received).toContain(expected) // indexOf
Expected value: "P2025"
Received array: [0, 401, 404]
Test source
1 | /**
2 | * L2 回归测试:收藏功能
3 | */
4 | import { test, expect } from '@playwright/test';
5 | import { apiGet, apiPost, apiDelete, initApiClient, disposeApiClient } from '../helpers/api-client';
6 |
7 | test.describe('收藏功能 (Favorites)', () => {
8 | test.beforeAll(async () => { await initApiClient(); });
9 | test.afterAll(async () => { await disposeApiClient(); });
10 |
11 | test('F01: 获取收藏列表 GET /api/favorites', async () => {
12 | const res = await apiGet('/api/favorites');
13 | expect(res.code).toBe(0);
14 | });
15 |
16 | test('F02: 添加收藏 POST /api/favorites', async () => {
17 | const res = await apiPost('/api/favorites', { audioId: '1' });
18 | // 可能成功(0)、重复(400)或需要认证(401)
19 | expect([0, 400, 401]).toContain(res.code);
20 | });
21 |
22 | test('F03: 取消收藏 DELETE /api/favorites/:id', async () => {
23 | const res = await apiDelete('/api/favorites/99999');
24 | // 可能成功(0)、未找到(404)或需要认证(401)
> 25 | expect([0, 401, 404]).toContain(res.code);
| ^ Error: expect(received).toContain(expected) // indexOf
26 | });
27 | });
28 |