From d2c3abea51fa82ae0f9dcb5aacc09e502ba3e6e7 Mon Sep 17 00:00:00 2001 From: Brad Decker Date: Mon, 23 Jan 2023 12:58:35 -0600 Subject: [PATCH] Refactor Errors E2E test to no longer rely upon a real error (#17332) Co-authored-by: Danica Shen --- test/e2e/tests/errors.spec.js | 14 +++----------- ui/index.js | 9 +++++++++ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/test/e2e/tests/errors.spec.js b/test/e2e/tests/errors.spec.js index 7538850cd..74f3ec502 100644 --- a/test/e2e/tests/errors.spec.js +++ b/test/e2e/tests/errors.spec.js @@ -43,12 +43,7 @@ describe('Sentry errors', function () { await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); // Trigger error - await driver.clickElement('[data-testid="eth-overview-send"]'); - await driver.fill( - 'input[placeholder="Search, public address (0x), or ENS"]', - '0x2f318C334780961FB129D2a6c30D0763d9a5C970', - ); - await driver.fill('input[placeholder="0"]', `-01`); + driver.executeScript('window.stateHooks.throwTestError()'); // Wait for Sentry request await driver.wait(async () => { const isPending = await mockedEndpoint.isPending(); @@ -60,11 +55,8 @@ describe('Sentry errors', function () { const [{ type, value }] = mockJsonBody.exception.values; const { participateInMetaMetrics } = extra.appState.store.metamask; // Verify request - assert.equal(type, 'BigNumber Error'); - assert.equal( - value, - 'new BigNumber() not a base 16 number: 0x-de0b6b3a7640000', - ); + assert.equal(type, 'TestError'); + assert.equal(value, 'Test Error'); assert.equal(level, 'error'); assert.equal(participateInMetaMetrics, true); }, diff --git a/ui/index.js b/ui/index.js index 643bc9760..36662f209 100644 --- a/ui/index.js +++ b/ui/index.js @@ -164,6 +164,15 @@ async function startApp(metamaskState, backgroundConnection, opts) { } function setupDebuggingHelpers(store) { + /** + * The following stateHook is a method intended to throw an error, used in + * our E2E test to ensure that errors are attempted to be sent to sentry. + */ + window.stateHooks.throwTestError = async function () { + const error = new Error('Test Error'); + error.name = 'TestError'; + throw error; + }; window.stateHooks.getCleanAppState = async function () { const state = clone(store.getState()); state.version = global.platform.getVersion();