Corrupt JSON Response
Corrupt a JSON response and assert that the app renders a parse-safe error instead of crashing.
await injectChaos(page, { seed: 42, network: { corruptions: [{ urlPattern: '/api/profile', strategy: 'malformed-json', probability: 1 }] },});await page.goto('/profile');await expect(page.locator('[data-testid="parse-error"]')).toBeVisible();expect((await getChaosLog(page)).some((event) => event.type === 'network:corruption' && event.applied)).toBe(true);cy.injectChaos({ seed: 42, network: { corruptions: [{ urlPattern: '/api/profile', strategy: 'malformed-json', probability: 1 }] },});cy.visit('/profile');cy.get('[data-testid="parse-error"]').should('be.visible');cy.getChaosLog().should((log) => { expect(log.some((event) => event.type === 'network:corruption' && event.applied)).to.equal(true);});await browser.url('/profile');await injectChaos(browser, { seed: 42, network: { corruptions: [{ urlPattern: '/api/profile', strategy: 'malformed-json', probability: 1 }] },});await $('#reload-profile').click();await expect($('[data-testid="parse-error"]')).toBeDisplayed();expect((await getChaosLog(browser)).some((event) => event.type === 'network:corruption' && event.applied)).toBe(true);await injectChaos(page, { seed: 42, network: { corruptions: [{ urlPattern: '/api/profile', strategy: 'malformed-json', probability: 1 }] },});await page.goto('http://localhost:3000/profile');await page.waitForSelector('[data-testid="parse-error"]');const log = await getChaosLog(page);if (!log.some((event) => event.type === 'network:corruption' && event.applied)) { throw new Error('Expected corrupt JSON chaos');}