Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

116
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda