Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

114
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!