Skip to content

Commit

Permalink
avoid using refs in e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasheyenbrock committed May 19, 2022
1 parent 912b692 commit 81cd37a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
7 changes: 2 additions & 5 deletions packages/graphiql/cypress/integration/init.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});
18 changes: 4 additions & 14 deletions packages/graphiql/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ declare namespace Cypress {
visitWithOp(op: Op): Chainable<Element>;
clickPrettify(): Chainable<Element>;
assertHasValues(op: Op): Chainable<Element>;
assertResult(result: MockResult): Chainable<Element>;
assertQueryResult(
op: Op,
expectedResult: MockResult,
Expand Down Expand Up @@ -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));
});
});

Expand Down

0 comments on commit 81cd37a

Please sign in to comment.