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\05-history.spec.ts >> 播放历史 (History) >> H04: 批量删除历史 DELETE /api/history/batch
- Location: regression\05-history.spec.ts:27:7
Error details
Error: expect(received).toContain(expected) // indexOf
Expected value: 400
Received array: [0, 401]
Test source
1 | /**
2 | * L2 回归测试:播放历史
3 | */
4 | import { test, expect } from '@playwright/test';
5 | import { apiGet, apiDelete, initApiClient, disposeApiClient } from '../helpers/api-client';
6 |
7 | test.describe('播放历史 (History)', () => {
8 | test.beforeAll(async () => { await initApiClient(); });
9 | test.afterAll(async () => { await disposeApiClient(); });
10 |
11 | test('H01: 获取历史列表 GET /api/history', async () => {
12 | const res = await apiGet('/api/history', { page: '1', pageSize: '5' });
13 | expect(res.code).toBe(0);
14 | expect(res.data).toBeDefined();
15 | });
16 |
17 | test('H02: 分页参数生效', async () => {
18 | const res = await apiGet('/api/history', { page: '1', pageSize: '2' });
19 | expect(res.code).toBe(0);
20 | });
21 |
22 | test('H03: 按日期筛选', async () => {
23 | const res = await apiGet('/api/history', { startDate: '2024-01-01' });
24 | expect(res.code).toBe(0);
25 | });
26 |
27 | test('H04: 批量删除历史 DELETE /api/history/batch', async () => {
28 | const res = await apiDelete('/api/history/batch');
29 | // 可能成功(0)或需要认证(401)
> 30 | expect([0, 401]).toContain(res.code);
| ^ Error: expect(received).toContain(expected) // indexOf
31 | });
32 | });
33 |