/// <reference types="cypress" />
describe('Responsive Breakpoint Testing', () => {
beforeEach(() => {
cy.visit('https://example.com');
});
it('shows mobile menu button at mobile breakpoint', () => {
cy.viewport(320, 480);
cy.get('[data-cy=mobile-menu-button]').should('be.visible');
cy.get('body').should('not.have.css', 'overflow-x', 'scroll');
});
it('shows horizontal navigation menu at tablet breakpoint', () => {
cy.viewport(768, 1024);
cy.get('[data-cy=horizontal-nav]').should('be.visible');
cy.get('[data-cy=mobile-menu-button]').should('not.be.visible');
cy.get('body').should('not.have.css', 'overflow-x', 'scroll');
});
it('shows full navigation bar at desktop breakpoint', () => {
cy.viewport(1280, 800);
cy.get('[data-cy=full-nav-bar]').should('be.visible');
cy.get('[data-cy=mobile-menu-button]').should('not.be.visible');
cy.get('body').should('not.have.css', 'overflow-x', 'scroll');
});
});This Cypress test suite checks the website layout at three common responsive breakpoints: mobile, tablet, and desktop.
We use cy.viewport(width, height) to simulate different screen sizes.
Each it block tests one breakpoint:
- At mobile size (320x480), it verifies the mobile menu button is visible.
- At tablet size (768x1024), it verifies the horizontal navigation menu is visible and mobile menu button is hidden.
- At desktop size (1280x800), it verifies the full navigation bar is visible and mobile menu button is hidden.
We also check that the body does not have horizontal scroll by asserting overflow-x CSS property is not set to scroll.
Selectors use data-cy attributes for stability and clarity.
This structure keeps tests clear, focused, and reliable.