Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

117
Vistas
Cypress test - including css change

I'm currently practicing tests with cypress on simple code. The most tests work within cypress except the button click which removes the class which disables the link. It seems like, that the changes to the css are not applied when testing. Apparently I should use a loader so that cypress can read the css, but my attempts so far have not worked. So my question is, if someone could recommend a loader or another way, so that the tests work.

My code:

class Headline {

    constructor(rootElement) {
        this.rootElement = rootElement;
        this.headline = this.rootElement.querySelectorAll('.headline');
        this.toggler =  this.rootElement.querySelectorAll('.button');
        this.init();
    }

    init(){
        this.toggler[0].addEventListener("click", () => {
            let newHeadline = document.getElementById('text').value;
            console.log(this.link)

            if(newHeadline.length === 0){
                alert("fehlender Input")
            }else{
                this.headline[0].innerHTML = newHeadline;
                console.log(document.getElementById('login').classList.remove('disabled'));
            }
        });
    }
}

document.querySelectorAll('.test').forEach((head) => {
    const input = new Headline(head);  
});
.disabled {
    pointer-events: none;
    cursor: default;
    text-decoration: none;
    color: lightgrey;
    
}
<div class="test">
  <h1 class="headline">Hallo</h1>
  <label for="text">New Headline:</label>
  <input type="text" id="text" name ="text" class="input_text" placeholder="newHeadline">
  <button class="button">Submit</button>
</div>

<a href="/page/login.html" id="login" class="disabled">Login</a>

and here is my cypress test

it('submit new headline', () => {
cy.visit('http://localhost:8080/')


cy.get('input[name="text"]').type('hahahahhahhhhhhhhhhhhhhhh');
cy.get('.button').click();

cy.get('#login').click();})
almost 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Your test should work as is if the css is loaded as part of the page. I'm not sure where it resides, so it's hard to make suggestion on that, but if you are just practicing testing, you could just include it in the html like this:

<style>
  .disabled {
    pointer-events: none;
    cursor: default;
    text-decoration: none;
    color: lightgrey;
  }
</style>

in addition, you could also test if the class is being added

describe("empty spec", () => {
  it("submit new headline", () => {
    cy.visit("http://localhost:8080/");
    cy.get('input[name="text"]').type("hahahahhahhhhhhhhhhhhhhhh");

    cy.get("#login").should("have.class", "disabled"); // is disabled?
    cy.get(".button").click();
    cy.get("#login").should("not.have.class", "disabled"); // is enabled?
    cy.get("#login").click();
  });
});

but, obviously, that's checking whether the class is added, not whether the link is actually disabled

almost 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda