# 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\07-comments.spec.ts >> 评论系统 (Comments) >> C03: 删除评论 DELETE /api/comments/:id - Location: regression\07-comments.spec.ts:29:7 # Error details ``` Error: expect(received).toContain(expected) // indexOf Expected value: 405 Received array: [0, 401, 404] ``` # Test source ```ts 1 | /** 2 | * L2 回归测试:评论系统 3 | * 注意:评论 API 需要认证,且路径为 /api/comments/:chapterId 4 | */ 5 | import { test, expect } from '@playwright/test'; 6 | import { apiGet, apiPost, apiDelete, initApiClient, disposeApiClient } from '../helpers/api-client'; 7 | 8 | test.describe('评论系统 (Comments)', () => { 9 | test.beforeAll(async () => { await initApiClient(); }); 10 | test.afterAll(async () => { await disposeApiClient(); }); 11 | 12 | // 评论需要 chapterId 参数,且需要认证 13 | test('C01: 获取评论列表 GET /api/comments/:chapterId', async () => { 14 | const res = await apiGet('/api/comments/1'); 15 | // 可能成功(0)、未找到(404)或需要认证(401) 16 | expect([0, 401, 404]).toContain(res.code); 17 | }); 18 | 19 | test('C02: 创建评论 POST /api/comments', async () => { 20 | const res = await apiPost('/api/comments', { 21 | chapterId: 1, 22 | content: '[自动化测试] 测试评论内容', 23 | rating: 5, 24 | }); 25 | // 可能成功(0)、参数错误(400)或需要认证(401) 26 | expect([0, 400, 401]).toContain(res.code); 27 | }); 28 | 29 | test('C03: 删除评论 DELETE /api/comments/:id', async () => { 30 | const res = await apiDelete('/api/comments/99999'); 31 | // 需要认证,未找到或成功 > 32 | expect([0, 401, 404]).toContain(res.code); | ^ Error: expect(received).toContain(expected) // indexOf 33 | }); 34 | }); ```