|
| 1 | +Cypress.on("uncaught:exception", (err, runnable) => { |
| 2 | + // returning false here prevents Cypress from |
| 3 | + // failing the test |
| 4 | + return false |
| 5 | +}) |
| 6 | + |
| 7 | +before(() => { |
| 8 | + cy.exec( |
| 9 | + `npm run update -- --file content/error-recovery/static-query.json --restore` |
| 10 | + ) |
| 11 | + cy.exec( |
| 12 | + `npm run update -- --file src/pages/error-handling/static-query-result-runtime-error.js --restore` |
| 13 | + ) |
| 14 | +}) |
| 15 | + |
| 16 | +after(() => { |
| 17 | + cy.exec( |
| 18 | + `npm run update -- --file content/error-recovery/static-query.json --restore` |
| 19 | + ) |
| 20 | + cy.exec( |
| 21 | + `npm run update -- --file src/pages/error-handling/static-query-result-runtime-error.js --restore` |
| 22 | + ) |
| 23 | +}) |
| 24 | + |
| 25 | +const errorPlaceholder = `false` |
| 26 | +const errorReplacement = `true` |
| 27 | + |
| 28 | +describe(`testing error overlay and ability to automatically recover from runtime errors (static queries variant)`, () => { |
| 29 | + it(`displays content initially (no errors yet)`, () => { |
| 30 | + cy.visit( |
| 31 | + `/error-handling/static-query-result-runtime-error/` |
| 32 | + ).waitForRouteChange() |
| 33 | + cy.getTestElement(`hot`).invoke(`text`).should(`contain`, `Working`) |
| 34 | + cy.getTestElement(`results`) |
| 35 | + .invoke(`text`) |
| 36 | + .should(`contain`, `"hasError": false`) |
| 37 | + }) |
| 38 | + |
| 39 | + it(`displays error with overlay on runtime errors`, () => { |
| 40 | + cy.exec( |
| 41 | + `npm run update -- --file content/error-recovery/static-query.json --replacements "${errorPlaceholder}:${errorReplacement}" --exact` |
| 42 | + ) |
| 43 | + |
| 44 | + // that's the exact error we throw and we expect to see that |
| 45 | + cy.getOverlayIframe().contains(`Static query results caused runtime error`) |
| 46 | + // contains details |
| 47 | + cy.getOverlayIframe().contains( |
| 48 | + `src/pages/error-handling/static-query-result-runtime-error.js` |
| 49 | + ) |
| 50 | + cy.screenshot() |
| 51 | + }) |
| 52 | + |
| 53 | + it(`can recover without need to refresh manually`, () => { |
| 54 | + cy.exec( |
| 55 | + `npm run update -- --file content/error-recovery/static-query.json --replacements "${errorReplacement}:${errorPlaceholder}" --exact` |
| 56 | + ) |
| 57 | + cy.exec( |
| 58 | + `npm run update -- --file src/pages/error-handling/static-query-result-runtime-error.js --replacements "Working:Updated" --exact` |
| 59 | + ) |
| 60 | + |
| 61 | + cy.getTestElement(`hot`).invoke(`text`).should(`contain`, `Updated`) |
| 62 | + cy.getTestElement(`results`) |
| 63 | + .invoke(`text`) |
| 64 | + .should(`contain`, `"hasError": false`) |
| 65 | + |
| 66 | + cy.assertNoOverlayIframe() |
| 67 | + cy.screenshot() |
| 68 | + }) |
| 69 | +}) |
0 commit comments