Skip to content

Fix TypeError: Wait for cytoscape instance to be ready before taking snapshot#173

Open
Copilot wants to merge 9 commits intomasterfrom
copilot/fix-snapshots-typeerror
Open

Fix TypeError: Wait for cytoscape instance to be ready before taking snapshot#173
Copilot wants to merge 9 commits intomasterfrom
copilot/fix-snapshots-typeerror

Conversation

Copy link

Copilot AI commented Feb 8, 2026

Cypress snapshot test fails when win.cyto is undefined, blocking snapshot generation:

TypeError: Cannot read properties of undefined (reading 'fit')
  at Context.eval (webpack:///./cypress/e2e/e2e/loadDesign.js:53:18)

Changes

  • Added proper wait mechanism using cy.window().its('cyto').should('exist') to wait for cytoscape instance
  • Leverages Cypress's built-in retry-ability to poll until cytoscape is ready
  • Test will now fail explicitly if cytoscape is not available within timeout
  • Chained .then() to execute fit() and center() operations once cytoscape is confirmed to exist
// Wait for cytoscape instance to be available and then fit/center
cy.window().its('cyto').should('exist').then((cytoscape) => {
    cytoscape.fit();
    cytoscape.center();
});

This ensures snapshots are only captured when the cytoscape canvas is fully loaded and properly positioned, preventing screenshots from being taken with an incomplete or missing canvas.

Original prompt

This section details on the original issue you should resolve

<issue_title>Snapshots fail with TypeError: Cannot read properties of undefined (reading 'fit')</issue_title>
<issue_description>### Description

     TypeError: Cannot read properties of undefined (reading 'fit')
      at Context.eval (webpack:///./cypress/e2e/e2e/loadDesign.js:53:18)

Contributor Resources and Handbook

The layer5.io website uses Gatsby, React, and GitHub Pages. Site content is found under the master branch.

Join the Layer5 Community by submitting your community member form.
</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits February 8, 2026 19:50
Co-authored-by: leecalcote <7570704+leecalcote@users.noreply.github.com>
Co-authored-by: leecalcote <7570704+leecalcote@users.noreply.github.com>
Co-authored-by: leecalcote <7570704+leecalcote@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix snapshots failing with TypeError reading 'fit' Fix TypeError on undefined cytoscape instance in snapshot test Feb 8, 2026
Copilot AI requested a review from leecalcote February 8, 2026 19:53
@leecalcote leecalcote marked this pull request as ready for review February 9, 2026 00:50
Copilot AI review requested due to automatic review settings February 9, 2026 00:50
@leecalcote
Copy link
Contributor

@copilot don't do this. Figure out another way to wait for cytoscape to be ready. There is no point in continuing with a screenshot if cytoscape isn't ready.

@github-actions
Copy link

github-actions bot commented Feb 9, 2026

Co-authored-by: leecalcote <7570704+leecalcote@users.noreply.github.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a Cypress E2E snapshot test failure by guarding viewport operations when the Cytoscape instance isn’t available on window, allowing snapshot generation to proceed.

Changes:

  • Add a null check around win.cyto before calling .fit() / .center()
  • Log a Cypress runner-visible message when Cytoscape is unavailable

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +51 to +52

// Wait for cytoscape instance to be available
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

captureSnapshot is passed a window argument from the caller, but it calls cy.window() again and uses win instead, leaving the window parameter unused. Consider either using the passed-in window to read window.cyto, or removing the window parameter to avoid confusion and an extra Cypress command.

Copilot uses AI. Check for mistakes.
Copilot AI and others added 4 commits February 9, 2026 00:53
Co-authored-by: leecalcote <7570704+leecalcote@users.noreply.github.com>
Co-authored-by: leecalcote <7570704+leecalcote@users.noreply.github.com>
Co-authored-by: leecalcote <7570704+leecalcote@users.noreply.github.com>
Co-authored-by: leecalcote <7570704+leecalcote@users.noreply.github.com>
Copy link
Author

Copilot AI commented Feb 9, 2026

@copilot don't do this. Figure out another way to wait for cytoscape to be ready. There is no point in continuing with a screenshot if cytoscape isn't ready.

Updated to wait for cytoscape instance to be ready using cy.window().its('cyto').should('exist'). The test will now properly retry until cytoscape is available or fail with a timeout if it's not ready. Changes in a90489e.

Copilot AI changed the title Fix TypeError on undefined cytoscape instance in snapshot test Fix TypeError: Wait for cytoscape instance to be ready before taking snapshot Feb 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Snapshots fail with TypeError: Cannot read properties of undefined (reading 'fit')

3 participants