DEV Community

Ola Johansson
Ola Johansson

Posted on • Edited on

1

Test horizontal scroll overflow on mobile devices with Cypress

One bug that appears now and then is that some element on the page is overflowing and makes the entire page overflow. I wanted to create a test in Cypress that make sure this doesn't happen. But i had a really hard time finding exactly how to do it.

Finally i realized i could make use of the scrollTo feature in Cypress.

it("should not have side scroll on about", function () {
   cy.viewport("iphone-6");
   cy.visit("/software/spotify/about/");

  cy.scrollTo("topRight");
  cy.window().its("scrollX").should("equal", 0);
});
Enter fullscreen mode Exit fullscreen mode

So what this does is that it set the viewport to an iPhone 6, go to a page on the site, it scroll to the top right corner AND then if scrollX is larger than zero then cypress managed to move the entire page i.e. i have a bug that caused a sidebar scroll on the page.

Of course this bug is usually caused by some bad data but i least i can catch some of the issues this way.

AWS Q Developer image

Your AI Code Assistant

Ask anything about your entire project, code and get answers and even architecture diagrams. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Start free in your IDE

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay