From 81cd37a28ff3fc6b0aa018685bac9f9c40f8c855 Mon Sep 17 00:00:00 2001 From: Thomas Heyenbrock Date: Thu, 19 May 2022 11:32:12 +0200 Subject: [PATCH] avoid using refs in e2e tests --- .../graphiql/cypress/integration/init.spec.ts | 7 ++----- packages/graphiql/cypress/support/commands.ts | 18 ++++-------------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/packages/graphiql/cypress/integration/init.spec.ts b/packages/graphiql/cypress/integration/init.spec.ts index f4802d7aca8..8e1cf4cf40c 100644 --- a/packages/graphiql/cypress/integration/init.spec.ts +++ b/packages/graphiql/cypress/integration/init.spec.ts @@ -48,11 +48,8 @@ describe('GraphiQL On Initialization', () => { it('Shows the expected error when the schema is invalid', () => { cy.visit(`/?bad=true`); cy.wait(200); - cy.window().then(w => { - // @ts-ignore - const value = w.g.resultComponent.viewer.getValue(); - // this message changes between graphql 15 & 16 - expect(value).to.contain('Names must'); + cy.get('section#graphiql-result-viewer').should(element => { + expect(element.get(0).innerText).to.contain('Names must'); }); }); }); diff --git a/packages/graphiql/cypress/support/commands.ts b/packages/graphiql/cypress/support/commands.ts index 30d7ca99d79..74bca825e4c 100644 --- a/packages/graphiql/cypress/support/commands.ts +++ b/packages/graphiql/cypress/support/commands.ts @@ -32,7 +32,6 @@ declare namespace Cypress { visitWithOp(op: Op): Chainable; clickPrettify(): Chainable; assertHasValues(op: Op): Chainable; - assertResult(result: MockResult): Chainable; assertQueryResult( op: Op, expectedResult: MockResult, @@ -90,19 +89,10 @@ Cypress.Commands.add('assertQueryResult', (op, mockSuccess, timeout = 200) => { cy.visitWithOp(op); cy.clickExecuteQuery(); cy.wait(timeout); - cy.window().then(w => { - // @ts-ignore - const value = w.g.resultComponent.viewer.getValue(); - expect(value).to.deep.equal(JSON.stringify(mockSuccess, null, 2)); - }); -}); - -Cypress.Commands.add('assertResult', (expectedResult, timeout = 200) => { - cy.wait(timeout); - cy.window().then(w => { - // @ts-ignore - const value = w.g.resultComponent.viewer.getValue(); - expect(value).to.deep.equal(JSON.stringify(expectedResult, null, 2)); + cy.get('section#graphiql-result-viewer').should(element => { + // Replace "invisible" whitespace characters with regular whitespace + const response = element.get(0).innerText.replace(/[\u00a0]/g, ' '); + expect(response).to.equal(JSON.stringify(mockSuccess, null, 2)); }); });