Reputation: 3293
Would there be a way to test for how many classes are within an element? I see methods for being able to test if an element has a class and testing length. Is there a way to combine these two together?
Upvotes: 3
Views: 1507
Reputation: 8672
Try something like this:
cy.get('button')
.invoke('attr', 'class')
.then(classNames => classNames.split(' '))
.should('have.length', 2);
});
Upvotes: 5
Reputation: 3741
If you can provide a part of the HTML I can customise the code for you, but it should be something like this:
cy.get(<ELEMENT>)
.find('class')
.should('have.length', <NUMBER>)
This way you look for the , then look for the element 'class' within it. And verify that it present of times.
Upvotes: 0